A Fresh Cup is Mike Gunderloy's software development weblog, covering Ruby on Rails and whatever else I find interesting in the universe of software. I'm a full-time Rails developer and contributor, available for long- or short-term consulting, with solid experience in working as part of a distributed team. If you'd like to hire me, drop me a line. I'm also the author of Rails Rescue Handbook and Rails Freelancing Handbook.

Navigation
« Double Shot #312 | Main | Double Shot #311 »
Monday
13Oct2008

More Goodies from Rails 2.2

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.

    October 13, 2008 | Unregistered Commentermalcontent

    Array#second? third?...
    i find that a little abusive.
    it's more expressive, but come on!

    October 14, 2008 | Unregistered CommenterAJ

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Post:
     
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>