Monday
13Oct2008
More Goodies from Rails 2.2
Monday, October 13, 2008 at 3:03PM
You'll be seeing plenty about the big new Rails 2.2 features soon enough, I'm sure. But there is also a sprinkling of new helpers of one sort or another coming in this version. Here's a selection that you might like:
Model.find_last_by_attributes - The opposite of find_first_by_attributes.
Model.find_by_attributes! - Raises an exception instead of returning nil if nothing can be found.
Date and Time classes now supply past?, today?, and future? for comparisons.
Array#second through Array#tenth are aliases for Array#[1] through Array#[9]
Enumerable#several is the equivalent of collection.size > 1
Inflector#parameterize produces a URL-ready version of its input, for use in +to_param+.

Reader Comments (2)
I want find_or_new not find_or_create_by or find_or_initialize_by.
If I pass in he params and you can't find it I want a fresh and empty object.
Array#second? third?...
i find that a little abusive.
it's more expressive, but come on!