Skip to content

Instantly share code, notes, and snippets.

@ilake
Created January 21, 2010 08:25
Show Gist options
  • Save ilake/282669 to your computer and use it in GitHub Desktop.
Save ilake/282669 to your computer and use it in GitHub Desktop.
class ActiveRecord::Base
named_scope :conditions, lambda { |*args| {:conditions => args} }
end
def self.find_by(email, nick, firstname, lastname)
scope = self.scoped({})
scope = scope.conditions "members.email LIKE ?", "%#{email}%" unless email.blank?
scope = scope.conditions "members.nick LIKE ?", "%#{nick}%" unless nick.blank?
scope = scope.conditions "members.firstname LIKE ?", "%#{firstname}%" unless firstname.blank?
scope = scope.conditions "members.lastname LIKE ?", "%#{lastname}%" unless lastname.blank?
scope
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment