View Single Post
  #2 (permalink)  
Old October 8th, 2009, 05:45 PM
Antonio Cangiano Antonio Cangiano is offline
Registered User
Join Date: Apr 2009
Location: Toronto, Canada
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post

Hi Dave,

in that section I employed two different ways of specifying conditions. The simplest one is to use a hash:

Article.find(:all, :conditions => { :published => true }, :order => "published_at DESC")
This can also be expressed as an array whose first element is a string containing the parameterized condition. For example, the line above could be rewritten as follows:

Article.find(:all, :conditions => ["published = ?", true], :order => "published_at DESC")
Using an array is more flexible than a hash, because you can specify the condition however you wish. The hash only allows you to specify an exact value to match one or more columns.

In fact, later in the same section of the book I used:

Article.find(:all, :conditions => [“published = ? AND published_at <= ?”, true,], :order => “published_at DESC”)
Notice how published_at is compared with <=. You couldn't express this with the hash syntax.

I hope this helps clarify the issue for you. If it doesn't, please don't hesitate to ask further questions.