My highlights from the new Rails 3.2.3

I’ve been reading up on the news in Rails 3.2 and here are the stuff I think is worth highlighting to remember :)

Active record

Fetch only the “name” column from the model.

Model.pluck :name

Fetch unique only

Model.select(:name).uniq

Fetch first, or if it doesn’t exist, create it

Model.where(:name => "Björn").first_or_create!

Other nifty stuff

Safe Constantize

"Model".safe_constantize

Note: The old method constantize throwed an Error when it couldn’t make it. With safe_constantize it returns nil instead.

Adding an index to a column when generating model/migration

rails g migration AddCoolModelToAwesomeModel cool_model_id:integer:index

And also…

  • Faster development mode
  • Automatic query explains