Ruby Quicktips Logo

Ruby Quicktips

Random Ruby and Rails tips.
This blog is dedicated to deliver short, interesting and practical tidbits of the Ruby language and Ruby on Rails framework. Read more...

Your submissions are more than welcome!
Aug 25 ’10

Find more than one ActiveRecord Object at a time

Everybody knows that you can retrieve an ActiveRecord object like this:

user = User.find(41)
=> #<User id: 41>

But did you know that you can pass multiple ids to the find method?

user = User.find(1, 2, 5)
=> [#<User id: 1>, #<User id: 2>, #<User id: 5>]

Principle of least surprise.

11 notes 0 comments (via rubyloveinfo)

  1. rubyquicktips reblogged this from rubyloveinfo
  2. refresherate reblogged this from rubyloveinfo
  3. rubyloveinfo posted this

Comments

You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.

blog comments powered by Disqus