Devise Forgot your password creates a link from localhost to the product?

We use the standard version of the forgotten password:

<p>Hello <%= @resource.email %>!</p> <p>Someone has requested a link to change your password, and you can do this through the link below.</p> <p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p> 

During production, this generates a localhost URL for Change Password:

 http://localhost:3000/users/password/edit?reset_password_token=amqs2q9NcM1FerHKhmzV 

This is strange if the production.rb file has our domain:

 config.action_mailer.default_url_options = { :host => 'mysite.com' } 

Why is mysite.com not used in the URL? Ideas?

thanks

+7
source share
3 answers

I assume that config.action_mailer.default_url_options being overwritten somewhere. Do you have a file in config/initializers that affects ActionMailer ?

Try running rails console in your production box and see what

 ActionMailer::Base.default_url_options[:host] 

coming back.

+17
source

My problem was in config / initializers / setup_mail.rb

+1
source

I fixed this by simply adding port to config.action_mailer.default_url_options which Devise always tells us to do during installation, but many of us ignore it.

 config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 

this is for development.rb anyway.

In production, the port value will be a variable - $PORT , because Heroku dynamically generates the port.

0
source

All Articles