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

Tags: , , ,

This entry was posted on Sunday, March 8th, 2009 at 7:47 pm and is filed under project, rails, rubyonrails. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “query interface”

  1. Aleksander Pawel Says:

    Cool. Your blog looks great, and I’m glad i’ve found something here worth adding to my favorites.

Leave a Reply