first!

first!() Instance Public methods Same as first but raises ActiveRecord::RecordNotFound if no record is found. Note that first! accepts no arguments.

first

first(limit = nil) Instance Public methods Find the first record (or first N records if a parameter is supplied). If no order is defined it will order by primary key. Person.first # returns the first object fetched by SELECT * FROM people Person.where(["user_name = ?", user_name]).first Person.where(["user_name = :u", { u: user_name }]).first Person.order("created_on DESC").offset(5).first Person.first(3) # returns the first three objects fetched by SELECT * FROM people LIMIT 3 Ra

find_by!

find_by!(*args) Instance Public methods Like find_by, except that if no record is found, raises an ActiveRecord::RecordNotFound error.

find_by

find_by(*args) Instance Public methods Finds the first record matching the specified conditions. There is no implied ordering so if order matters, you should specify it yourself. If no record is found, returns nil. Post.find_by name: 'Spartacus', rating: 4 Post.find_by "published_at < ?", 2.weeks.ago

find

find(*args) Instance Public methods Find by id - This can either be a specific id (1), a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]). If no record can be found for all of the listed ids, then RecordNotFound will be raised. If the primary key is an integer, find by id coerces its arguments using to_i. Person.find(1) # returns the object for ID = 1 Person.find("1") # returns the object for ID = 1 Person.find("31-sarah") # returns the object for ID = 31 Pers

fifth!

fifth!() Instance Public methods Same as fifth but raises ActiveRecord::RecordNotFound if no record is found.

fifth

fifth() Instance Public methods Find the fifth record. If no order is defined it will order by primary key. Person.fifth # returns the fifth object fetched by SELECT * FROM people Person.offset(3).fifth # returns the fifth object from OFFSET 3 (which is OFFSET 7) Person.where(["user_name = :u", { u: user_name }]).fifth

exists?

exists?(conditions = :none) Instance Public methods Returns true if a record exists in the table that matches the id or conditions given, or false otherwise. The argument can take six forms: Integer - Finds the record with this primary key. String - Finds the record with a primary key corresponding to this string (such as '5'). Array - Finds the record that matches these find-style conditions (such as ['name LIKE ?', "%#{query}%"]). Hash - Finds the record that matches these

name

name() Class Public methods

email

email() Class Public methods