Skip to content

Instantly share code, notes, and snippets.

@shekibobo
Last active August 29, 2015 14:12
Show Gist options
  • Save shekibobo/2c5cceb4310548125c9f to your computer and use it in GitHub Desktop.
Save shekibobo/2c5cceb4310548125c9f to your computer and use it in GitHub Desktop.
Attempt to send recovery email to alt_email
# in config/initializers/devise/mailers/helpers.rb (I think)
module Devise
module Mailers
module Helpers
def headers_for(action, opts)
headers = {
subject: subject_for(action),
# overriding this one using the one from the form
to: resource.notification_email,
from: mailer_sender(devise_mapping),
reply_to: mailer_reply_to(devise_mapping),
template_path: template_paths,
template_name: action
}.merge(opts)
@email = headers[:to]
headers
end
end
end
end
class User
# new idea here, not sure if it will work.
attr_writer :notification_email
def notification_email
# make sure you can't send to just any old email
if @notification_email.present? && [email, alt_email].include? @notification_email
@notification_email
else
email
end
end
def send_reset_password_instructions(attributes={})
recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
# Set this virtual attribute on the model
recoverable.notification_email = attributes[:email]
recoverable.send_reset_password_instructions if recoverable.persisted?
recoverable
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment