I’ve talked a lot about the Nifty Generators gem, created by Ryan Bates of Railscasts (see my introductions to nifty_layout, nifty_config, and nifty_scaffold). When I began experimenting with Rails 3 I noticed that the gem was not yet Rails 3 compatible according to RailsPlugins.org, but I’m happy to report (along with RailsPlugins.org users eggie5 and dgerton) that it’s working fine—you just need to change a few things about how you use it. Here’s what you need to do to get rolling:
Unlike apps written in previous versions of Rails, your Rails 3 app needs to know you’re using Nifty Generators. Easy enough: Add the following line to your Gemfile:
then install it if necessary, using Bundler:
This is the biggest difference, and it’s actually pretty minor. Replace the underscore in the old way of using the generator with a colon. So the old way of generating a scaffold, like
For a list of all four Nifty Generators’ new syntax, just type
If you liked my series on practical advice for adding reliable tests to your Rails apps, check out the expanded ebook version. Lots of additional, exclusive content and a complete sample Rails application.
Ruby on Rails news and tips, and other ideas and surprises from Aaron at Everyday Rails. Delivered to your inbox on no particular set schedule.