Use find_by instead of where + first
What does this MR do?
Update usages of where.first
and change them to use find_by
instead.
# bad
User.where(name: 'Bruce').first
User.where(name: 'Bruce').take
# good
User.find_by(name: 'Bruce')
I've tried to enforce this automatically with Rails/FindBy
in the .rubocop
file which is supposed to be enabled by default but doesn't work at all.
References:
- https://github.com/rubocop-hq/rails-style-guide#find_by
- https://docs.rubocop.org/projects/rails/en/stable/cops_rails/#railsfindby
I've modified this with the help of Atom:
Closes #211877 (closed)