instance method
find_by
Ruby on Rails 4.2.9
Since v4.0.13Signature
find_by(*args)
Finds the first record matching the specified conditions. There is no implied ordering so if order matters, you should specify it yourself.
If no record is found, returns nil.
Post.find_by name: 'Spartacus', rating: 4 Post.find_by "published_at < ?", 2.weeks.ago
Parameters
-
argsrest
Source
# File activerecord/lib/active_record/relation/finder_methods.rb, line 83
def find_by(*args)
where(*args).take
rescue RangeError
nil
end
Defined in activerecord/lib/active_record/relation/finder_methods.rb line 83
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::FinderMethods