Method: Devise::Models::Authenticatable::ClassMethods#find_or_initialize_with_error_by
- Defined in:
- lib/devise/models/authenticatable.rb
#find_or_initialize_with_error_by(attribute, value, error = :invalid) ⇒ Object
Find an initialize a record setting an error if it can’t be found.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/devise/models/authenticatable.rb', line 97 def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc: if value.present? conditions = { attribute => value } record = find(:first, :conditions => conditions) end unless record record = new if value.present? record.send(:"#{attribute}=", value) else error = :blank end record.errors.add(attribute, error) end record end |