Three Ways to Make Database Queries in Rails

active_recordrails

July 24, 2019  |  1 min read

In Rails, querying the record(s) from database can be done through the following methods:

  1. find(*arguments)

  2. find_by(argument, *arguments)

    • Finds the first record matching the specified conditions
    • Returns nil if no record is found
    • find_by!(argument, *arguments) raises ActiveRecord::RecordNotFound like find() if no record is found
  3. where(options = :chain, *rest)

Refs