Left of the Dev

Use Nifty Generators in Rails 3

By Aaron Sumner, July 30, 2010.

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:

1. Include Nifty Generators in your Gemfile

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:

  gem 'nifty-generators', '>= 0.4.0'

then install it if necessary, using Bundler:

  $ bundle install

2. Know the command line changes

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

  $ script/generate nifty_scaffold book title:string author_id:integer description:text

becomes

  $ rails generate nifty:scaffold book title:string author_id:integer description:text

For a list of all four Nifty Generators’ new syntax, just type

  $ rails generate -h

Test Rails apps (mostly) out of the box!

Join me on a thought experiment: How does my time-tested approach to testing Ruby on Rails applications apply to the tools we get from the framework? Whether you're new to Rails testing, or curious about the default testing stack, Testing Rails from Scratch gives you a pragmatic, end-to-end introduction to test-driven development. Covers Rails 8.1 and Ruby 4.0. Early release now available for sale on Leanpub!

Test with confidence!

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. Updated in 2026 to Rails 8.1 and Ruby 4.0!

Newsletter

Software development news and tips, and other ideas and surprises from Aaron at Left of the Dev. Delivered to your inbox on no particular set schedule.