Created
February 6, 2012 20:08
-
-
Save luckyruby/1754500 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.search(params) | |
conditions = [] | |
matches = [] | |
if params[:first_name].present? | |
conditions << "first_name = ?" | |
matches << params[:first_name] | |
end | |
if params[:last_name].present? | |
conditions << "last_name = ?" | |
matches << params[:last_name] | |
end | |
if params[:email].present? | |
conditions << "email = ?" | |
matches << params[:email] | |
end | |
User.select("first_name, last_name, email").where([conditions.join(" AND ")].concat matches).where(:active => true) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment