I am trying to add a method to Devise :: Mailer, the method must send mail to the user with a link in order to set his own password when the administrator creates a new user without a password.
Devise::Mailer.class_eval do
def set_password_instructions(record)
setup_mail(record, :set_password_instructions)
end
end
If I put this in / lib and requested it in application.rb, it will boot up to the real Devise.
If I require it at the top of my user.rb, it works the first time, with another unknown set_password_instructions method at another time.
It only works when adding the above code directly to user#send_set_password_instructions
user.rb:
def send_set_password_instructions
Devise::Mailer.class_eval do
def set_password_instructions(record)
setup_mail(record, :set_password_instructions)
end
end
generate_reset_password_token!
::Devise.mailer.set_password_instructions(self).deliver
end
Could someone shed light on this strange behavior?
Looks like Devise.mailer is reloading the Devise :: Mailer class?
Mirko source
share