I’m creating a password reset functionality for my site in rails and in my mailer password_reset.text.erb file I’m currently sending
http://localhost:3000/password_resets/<%=@user.password_reset_token%>/edit/
in my development environment. This will hit my controller for password reset and redirect the user to edit the password if the token matches with the saved model.
However, I’d like to configure this dynamically so when I deploy to heroku it will know to change that to mywebsite.com/password_resets/...
How would I do this?
EDIT:
def password_reset(user)
@user = user
mail(to: user.email, subject: "Bitelist Password Reset")
end
Typically I configure the host information for the mailer in an appropriate
config/environmentfile.You can take a look at the “Generating URLs” section of this page: http://rails.rubyonrails.org/classes/ActionMailer/Base.html
With that configuration set typical routing structures seem to work quite nicely. I am not 100% positive what routes will be available in your situation so you may still need to construct the full URL somewhat manually to include the reset token component.
To generate the actual URLs you can potentially use named routes if your routes are set up in a way that you have a named route that takes a user token. i.e.
If you do not have the token integrated into an existing route you may need to manually build the URL:
or even build it completely manually using
default_url_options[:host]and then add the rest that you have above.If need be you could also set the host at request time although that may be overkill (and will not be thread safe).