Method: ActiveRecord::FinderMethods#find_by
- Defined in:
- activerecord/lib/active_record/relation/finder_methods.rb
#find_by(arg, *args) ⇒ Object
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
111 112 113 |
# File 'activerecord/lib/active_record/relation/finder_methods.rb', line 111 def find_by(arg, *args) where(arg, *args).take end |