Merging search criteria with merge_conditions

  def search(params = {})
    cond = []
    cond << ["name LIKE ?", params[:name] + '%'] unless params[:name].blank?
    cond << ["email = ?",   params[:email]]       unless params[:email].blank?
    conditions = cond.map { |c| User.merge_conditions(c) }.join(' AND ')
    User.find(:all, :conditions => conditions)
  end

2 Comments

  1. Thanks a lot for this ! I just implemented it in my code, works like a charm ! THANKS !!!

Comments are closed.

© 2024 Gudasoft

Theme by Anders NorénUp ↑