Best way to find a single record using ActiveRecord 3 / Arel?

John Bachir picture John Bachir · Jun 13, 2011 · Viewed 31.1k times · Source

Where I used to do this:

Foo.find_by_bar('a-value')

I can now do this:

Foo.where(:bar => 'a-value').limit(1).first

Is this recommended? Is this the best way? Should I continue to use the "old" way because it continues to be useful syntactic sugar, or is there an Even Better way I can do that now, which will support chaining and all the other good stuff?

Answer

SureshCS picture SureshCS · Feb 10, 2014

Rails 4 :

Foo.find_by bar: 'a_value' , wibble: 'a wibble value'