A method that can retrieve records that match the conditions in the table in the form of an array.
controller
Model name.where("conditions")
The where method has a symbol specification and a character string specification.
controller
Model name.where(Column name:conditions)
#When retrieving all records containing the characters "Taro" from the name column of the users table
User.where(name: "Taro")
controller
Model name.where("Column name=conditions")
#When retrieving all records containing the characters "Taro" from the name column of the users table
User.where("name = 'Taro'")
controller
User.where("id > ?", 5)
#You can get all records with id 5 or higher.
controller
User.where(name: "Taro", age: 25)
#You can get all records with "Taro" in the name column and "25" in the age column.
controller
User.where(name: "Taro").or(User.where(age: 25))
#You can get all records with name column "Taro" or age column "25".
Recommended Posts