Ruby

Ruby

Made by DeepSource

Use of find_by_* detected RB-RL1017

Anti-pattern
Major

Favor the use of find_by over where.take and find_by_attribute when you need to retrieve a single record by one or more attributes and return nil when the record is not found.

Bad practice

User.where(email: email).take
User.where(first_name: 'Bruce', last_name: 'Wayne').take

User.find_by_email(email)
User.find_by_first_name_and_last_name('Bruce', 'Wayne')

Recommended

User.find_by(email: email)
User.find_by(first_name: 'Bruce', last_name: 'Wayne')