Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created December 2, 2020 07:48
Show Gist options
  • Select an option

  • Save dpaluy/8f53259e30c87cf9ed67fa108ddba2a2 to your computer and use it in GitHub Desktop.

Select an option

Save dpaluy/8f53259e30c87cf9ed67fa108ddba2a2 to your computer and use it in GitHub Desktop.
Send confirmation token with Welcome email
class UserMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
default template_path: 'users/mailer' # to make sure that your mailer uses the devise views
def welcome_reset_password_instructions(user)
create_reset_password_token(user)
mail(to: user.email, subject: 'Welcome to the New Site')
end
private
def create_reset_password_token(user)
raw, hashed = Devise.token_generator.generate(User, :reset_password_token)
@token = raw
user.reset_password_token = hashed
user.reset_password_sent_at = Time.now.utc
user.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment