Posts Tagged ‘find_by’

query interface

find_all : return multiple records
_by_* : replace * with your column
(false) : where complete like ‘false’
def incomplete
@tasks = Task.find_all_by_complete(false)
end
find : return single record
_by_* : replace * with your column
(false,:order => ‘created_at’ DESC) : where complete like ‘false’ and order by created_at descending
def last_incomplete
@task = Task.find_by_complete(false, :order => ‘created_at DESC’)
end