What are the differences between #where and #find?
Last updated
Was this helpful?
Last updated
Was this helpful?
The real difference is what they return when a record is found, or when it's not found. Consider the following examples:
The big difference with using #where
is you can chain commands because #where
actually returns an instance of ActiveRecord::Relation
:
Let's have a look at when you try to find a record that isn't existing:
So here, it's obvious that when you use find
to search for a record that isn't existing, you get an exception.
Read more about and in Rails API. Also, watch video by Ryan Bates (Railscasts).