Module: Devise::Models::Confirmable::ClassMethods

Defined in:
lib/devise/models/confirmable.rb

Instance Method Summary collapse

Instance Method Details

#confirm_by_token(confirmation_token) ⇒ Object

Find a user by it’s confirmation token and try to confirm it. If no user is found, returns a new user with an error. If the user is already confirmed, create an error for the user Options must have the confirmation_token



149
150
151
152
153
# File 'lib/devise/models/confirmable.rb', line 149

def confirm_by_token(confirmation_token)
  confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
  confirmable.confirm! if confirmable.persisted?
  confirmable
end

#confirmation_tokenObject

Generate a token checking if one does not already exist in the database.



156
157
158
# File 'lib/devise/models/confirmable.rb', line 156

def confirmation_token
  generate_token(:confirmation_token)
end

#send_confirmation_instructions(attributes = {}) ⇒ Object

Attempt to find a user by it’s email. If a record is found, send new confirmation instructions to it. If not user is found, returns a new user with an email not found error. Options must contain the user email



139
140
141
142
143
# File 'lib/devise/models/confirmable.rb', line 139

def send_confirmation_instructions(attributes={})
  confirmable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
  confirmable.resend_confirmation_token if confirmable.persisted?
  confirmable
end