On 5/13/06, Hampton <[EMAIL PROTECTED]> wrote:
Let's say you have params[:student] = { :last_name = "Catlin" }. And,
anything could have been passed in. Maybe a bunch of different attributes,
and we'd like to filter based on that.
Student.find_with (params[:student])
...which really works as...
Student.find_with(:last_name = "Catlin)
I've been exploring similar areas with my 'slice and dice' plugin
(svn://rubyforge.org//var/svn/popdog/slice_and_dice/tags/REL-0.1). It
alters sanitize_sql to allow conditions passed in a hash (in addition
to strings and arrays). i.e:
Student.find :all, :conditions => ["last_name = ?", "Catlin"]
can be written as:
Student.find :all, :conditions => {:first_name => "Catlin"}
This condition hash (hopefully) works not just in finder methods, but
also calculations, etc. It also allows slightly more complex clauses:
Book.find :all, :conditions => {:price_more_than => 50}
Book.count :conditions => {:title_starts_with => "Zen and the art of"}
It'd be great if you released your code as a plugin. I'd like to see
how you've gone about implementing it, and anything I can learn/steal
for my own. If you've any comments on what I've done, I'd be glad to
hear them too.
Tom
--
email : tom at popdog.net
_______________________________________________
Rails-core mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-core