Quantcast
Channel: How to override Devise confirmation instructions - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How to override Devise confirmation instructions

$
0
0

I am using Devise and trying to create a new user(customer) programmatically and send the customer his password by email. I have created a custom mailer and have overridden the confirmation_instructions method. This code below works fine. After I programmatically create the customer, the customer is sent an email with the custom header "Bar" and a confirmation link is sent.

class CustomMailer < Devise::Mailer       helper :application # gives access to all helpers defined within `application_helper`.    include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`    def confirmation_instructions(record, token, opts={})        headers["Custom-header"] = "Bar"    super  endend

But I need to also send a password, so I tried this:

class CustomMailer < Devise::Mailer       helper :application # gives access to all helpers defined within `application_helper`.    include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`    def confirmation_instructions(record, token, opts={})        headers["Custom-header"] = "Bar"        @password = opts[:password]        super    endend

And I manually call the email method like this from my controller:

@customer_instance = Customer.new({ :email => customer_params[:email], :password => generated_password, :password_confirmation => generated_password, :first_name => customer_params[:first_name], :last_name => customer_params[:last_name] })@customer_instance.skip_confirmation!@customer_instance.saveCustomMailer.confirmation_instructions(@customer_instance, @customer_instance.confirmation_token, {password: generated_password}).deliver

The password gets sent fine, but the confirmation token does not get sent. How can I use Devise to create a confirmation token to pass in here? Or is there a different way of doing it where I don't need to pass the token in manually?


Viewing all articles
Browse latest Browse all 3

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>