In Rails, querying the record(s) from database can be done through the following methods:
-
- Find records by their IDs
- Raises exception (
ActiveRecord::RecordNotFound
) if no record is found
-
- Finds the first record matching the specified conditions
- Returns
nil
if no record is found find_by!(argument, *arguments)
raises ActiveRecord::RecordNotFound likefind()
if no record is found
-
where(options = :chain, *rest)
- Refer to How to Use The Rails Where Method (with Examples), starting from "Basic Where Conditions", for examples and their use cases