There’s now a convenient way to call Active Record finder methods when the query is based solely on AND ed equality conditions.
Before:
Article.find(:all, :conditions => [ "author_id = ? and status = ?", @author.id, 'published' ], :limit => 10)
Now:
Article.find(:all, :conditions => { :author_id => @author.id, :status => 'published' }, :limit => 10)
Instead of having to finagle with the SQL string and the correct number of ? placeholders – we can now just pass in the hash of parameters which will be AND ed together to form the SQL query.
Ahh, that’s nice.
tags: rubyonrails, rails

ORs besides the standard:conditions => ['this = ? OR that =?', @this, @that]The array form is to be used when the condition input is tainted and requires sanitization. The string form can be used for statements that don't involve tainted data. The hash form works much like the array form, except only equality is possible.