Using Rails Generators
Most people who start learning Rails today quickly learn about generators. They’re easy to use and very handy.
Still, like any other code-generation device, it’s important to understand what they’re doing when you use them. I thought that would go without saying, but I should know better. I remember back in the day of ATL COM programming on Windows, adoption of ATL really took off when Visual Studio added a few wizards to help you create COM components easily. The number of people who didn’t realize what it was doing was surprising. When the smallest bug or issue would come up, they were at a loss to know what their program was doing. To be fair, I also didn’t know what the wizards were doing when I started learning, either. I finally learned how to create COM components by hand (IDL….yuck), and once I did a couple, I knew everything I needed to know. Using the wizards after that was fun and helpful, since I knew how to change (or fix) anything I needed to after the wizard had generated its code.
Ok, back to the present… once in a while I notice that people don’t really understand Rails generators. I don’t really think it’s worth a blog post to explain all of them, but I did want to mention a quick tip that you might not already be aware of if you’ve just recently started with Rails: if you do this,
c:\myapp> ruby script\generate
(and then wait a minute) you’ll get a page showing all the options and generators available.
You can get specific help on a generator (say, the scaffold generator) like this:
c:\myapp> ruby script\generate scaffold
The help that’s emitted to the console is dense but usually quite complete.
Just do me one favor: after using a generator, learn what it did for you. There’s nothing a generator can do that you can’t do yourself. They just take the tedium out of some common Rails tasks that you’d otherwise have to do by hand.
Now, if you’d like to see an article on a specific generator, or have other questions about Rails generators, just drop us a comment here.
New to REST in Rails? Come to REST with Rails Oct 4, 2008, in Austin, TX




Thanks, Jeff. I’m definitely in the beginner camp and don’t have time to got to a training session, and am too cheap to buy a book. Articles like this help me learn. I’m aware of what generating a controller/model/migration does because I look at the output. I didn’t know you could get help by running “ruby script/genereate”; that’s a nice tip. Thanks.
Good artice, write more about basic things!