Where Builder for ActiveRecord plugin
Plugin details
Documentation
Install the plugin:
ruby script/plugin install http://invisible.ch/svn/projects/plugins/where
Uses a block to initialize the condition:
c = InVisible::Cond.new do month '<=', 11 year '=', 2005 name 'LIKE', 'ruby%' end c.where -> ["month <= ? and year = ? and name LIKE ?", 11, 2005, "ruby%"]
Lets say that you have this hash in your +params+ :
params = { :person => {:name => "dave" :city => "Yakima"}} c = InVisible::Cond.new do person '=', params[:person][:name] city '=', params[:person][:city] end MyModel.find(:all, :conditions => c.where)
or simpler:
MyModel.find_with_conditions( :all ) do person params[:person][:name] city params[:person][:city] end
to include direct SQL, use like this:
c = InVisible::Cond.new do sql "hosts.id = logs.host_id and hosts.name", 'like', "123.23.45.67" end
if a value needs to by typed (f.e. in Postgres: "ip < inet ?"), use a form of:
c = InVisible::Cond.new do ip '= inet', '123.34.56.78/24' end
to expand an existing condition, use the << method
c << ['age', '>', 30]
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago

