Skip to content

Instantly share code, notes, and snippets.

@luckyruby
Created February 6, 2012 20:08
Show Gist options
  • Save luckyruby/1754500 to your computer and use it in GitHub Desktop.
Save luckyruby/1754500 to your computer and use it in GitHub Desktop.
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