Custom variables in devise reset password instructions?

I need to configure the rails to create a description of the email messages for the reset password instructions.

for this I need to do two things.

  • Specify your own link URL so that its host / domain is based on specific business logic. This host and domain come from the browser URL, that is, the request object when the user clicks the forgot password. Therefore, I do not have a request object in delayed_job to handle it, because I need it, so I need to do this at some point in delayed_job, which sends an email.

  • Pass custom variables into the mailer view so that I can add to other logic for the view, hide and show bits as needed.

Can anyone help? I see that you can generate views of the development email program, but I also need to go through the various elements. Do I have to somehow override the functions myself in my user model and password controller, for example?

+4
source share
3 answers

So, after long jokes, searching and hacking with things ... it's just not possible. so I ended up writing my own email program and bypassing the reset password methods in the controllers to create my own reset token, set my variables that I need, called my usermailer .... and embedded url dev in my mail to return it, calling it as soon as the link to the reset link was clicked, and everything was fine then ....

I hated to rewrite the logic, but in the end it is the fastest and cleanest solution.

One approach that almost worked was using the non activerecord attribute in my user model to store the bits I needed and โ€œhackingโ€ that in the @resource editor in the development view, but it caused some sadness in this, as a result I went with the option above ...

+1
source

I needed to add source to include reset in the password view, this is what I implemented:

 class User < ActiveRecord::Base prepend ResetPasswordWithSource devise :recoverable .... end module User::ResetPasswordWithSource def send_reset_password_instructions(source=nil) @source = source super() end def send_devise_notification(notification, *args) args.last.merge!({ source: @source }) super end end 

From here, you can simply call user.send_reset_password_instructions('special_source')

And you can access the views via @options[:source] = 'special_source'

+1
source

I also struggled with this before I realized that declaring custom variables before calling super would work.

  def reset_password_instructions(record, token, opts={}) @custom_variable = "Greetings, world" # your gorgeous code mailer_object = super mailer_object end 
0
source

All Articles