is rails find
method deprecated?
in olden days, find(1)
preferred way find id.
is better use find_by(id:1)
instead of find(1)
?
neither method deprecated (as far know). difference between find
, find_by()
return when record not exist. if record id of 23 not exist, get:
model.find(23) => activerecord::recordnotfound: couldn't find model 'id'=23
or
model.find_by(id: 23) => nil
using find_by
more forgiving if you're making queries non-existent record possible because nil
value rather exception.
Comments
Post a Comment