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
© 2024 Gudasoft
Theme by Anders Norén — Up ↑
J April, 2009 at 4:56 pm
This method is public from 2.2.1
http://apidock.com/rails/v2.2.1/ActiveRecord/Base/merge_conditions/class
J January, 2010 at 3:16 am
Thanks a lot for this ! I just implemented it in my code, works like a charm ! THANKS !!!