Created
January 21, 2010 08:25
-
-
Save ilake/282669 to your computer and use it in GitHub Desktop.
This file contains 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
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