Skip to content

Files

Latest commit

 

History

History
23 lines (15 loc) · 526 Bytes

Rails-FindById.md

File metadata and controls

23 lines (15 loc) · 526 Bytes

Pattern: Use of where.first instead of find_by

Issue: -

Description

This rule enforces that ActiveRecord#find is used instead of where.take!, find_by!, and find_by_id! to retrieve a single record by primary key when you expect it to be found.

Examples

# bad
User.where(id: id).take!
User.find_by_id!(id)
User.find_by!(id: id)

# good
User.find(id)

Further Reading