Quantcast
Channel: Teach Me To Code » Ruby on Rails
Viewing all articles
Browse latest Browse all 34

Ruby on Rails: Nifty Generators

$
0
0

While looking at articles and resources about authentication in Ruby on Rails I ran across a set of generators written by Ryan Bates of Railscasts. You can find the nifty generators at http://github.com/ryanb/nifty-generators/tree/master

I ran the generators and have posted the resulting code at http://github.com/charlesmaxwood/nifty/tree/master.

Authentication

My favorite of the generators was actually the authentication generator.

script/generate nifty_authentication

The thing that surprised me about the nifty authentication generator was that it was actually faster to implement than even clearance was. It worked right off the bat and I was very impressed. It encrypts the password with a SHA1 hash and provides a complete, but simple authentication solution.

Config Files

Another useful generator is the nifty config generator. This generator creates a configuration .yml file in the /config directory and an initializer that automatically loads the config. If you generate the default config, you’ll wind up with a config file at /config/app_config.yml.

script/generate nifty_config

You can access config values using the APP_CONFIG constant. If you call your config by another name, it’s that file’s name in uppercase.

Scaffold

The nifty scaffold generator provides a lot of things that make it easy to develop a solid RESTful application. You get the following from the generator:

  • Routes
  • Migration
  • Model
  • Controller complete with RESTful actions
  • Views
  • Tests
script/generate nifty_scaffold recipe title:string directions:string author:references

The scaffolding isn’t perfect since the references to author wasn’t working on the new recipe form. I’m going to leave it that way so you can pull the code and have a look. The fix is pretty simple, but you should be able to experience the shortcoming so you’re aware of it.

Nifty Layout

Have you ever wished you had a generator that created a layout with basic CSS? Now you have one. It’s pretty simple. It generates the layouts you see on Ryan’s Railscasts. You can get it by running the generator.

script/generate nifty_layout

Get it now!

You can get these generators by installing the nifty_generators gem.

sudo gem install nifty-generators

Viewing all articles
Browse latest Browse all 34

Trending Articles