-
where
returns anActiveRecord::Relation
(not an array, even though it behaves much like one), which is a collection of model objects. If nothing matches the conditions, it simply returns an empty relation. -
find
(and its related dynamicfind_by_columnname
methods) returns a single model object. If nothing is found, anActiveRecord::RecordNotFound
exception is raised (but not with the dynamicfind_by_
methods).While
find
can return an Array of records—not a Relation—if given a list of IDs, usingwhere
is preferred since Rails 3. Many similar uses offind
are now deprecated or gone entirely.
So yes, if you only want and expect a single object, using find
is easier, as otherwise you must call Model.where.first
.
Note that old-style hash options to find
and many dynamic find_
methods are deprecated as of Rails 4.0 (see relevant release notes).