Skip to content

Instantly share code, notes, and snippets.

@masterkain
Created September 4, 2008 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masterkain/8750 to your computer and use it in GitHub Desktop.
Save masterkain/8750 to your computer and use it in GitHub Desktop.
conditions = Where.new
conditions.or('accounts.phone like ?', '%' + params[:search] + '%') unless params[:search].blank?
conditions.or('groups.name like ?', '%' + params[:search] + '%') unless params[:search].blank?
# new rails feature, :joins permit to have conditions based on the joined table.
# http://ryandaigle.com/articles/2008/7/7/what-s-new-in-edge-rails-easy-join-table-conditions
@accounts = Account.paginate(:page => params[:page] || 1, :joins => :group, :conditions => conditions, :include => :group)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment