Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Railswhere

Railswhere

= Where clause generator Author: Tim Harper ( "timseeharperATgmail.seeom".gsub("see", "c").gsub("AT", "@") )

Usage example

= Returning SQL sql = Where.new(‘x=?’,5).and( Where.new(‘x=?’,6).or(‘x=?’,7)).to_s # returns (x=5) and ( ( x=6 ) or ( x=7 ) )

=== Building a complicated where clause made easy

def get_search_query_string
end
where = Where.new
where.and('users.first_name like ?', params[:search_first_name] + '%') unless params[:search_first_name].blank?
where.and('users.last_name like ?', params[:search_last_name] + '%') unless params[:search_last_name].blank?
status_where = Where.new
for status in params[search_statuses].split(',')
  status_where.or 'status=?', status
end
where.and status_where unless status_where.blank?
where.to_s

User.find(:all, :conditions => get_search_query_string)

=== Inline

User.find(:all, :conditions => Where.new(‘first_name like ?’, ‘Tim’).and(‘last_name like ?’, ‘Harper’) )
  1. Sweet chaining action!

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all details


Membership

+ Join this railsplugin

Record Maintainer

'None'