Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise Forgot password is creating a link with localhost on product?

We're using the standard devise forgot password mailer:

<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>

On production this is generating a localhost url for Change Password:

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

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

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

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

Thanks

like image 467
AnApprentice Avatar asked Oct 26 '11 00:10

AnApprentice


3 Answers

My guess is that config.action_mailer.default_url_options is being overwritten somewhere. Do you have any file in config/initializers that affects ActionMailer?

Try running rails console on your production box and see what

ActionMailer::Base.default_url_options[:host]

returns.

like image 112
Alex Peattie Avatar answered Nov 05 '22 07:11

Alex Peattie


My problem was in config/initializers/setup_mail.rb

like image 1
John Robinson Jr. Avatar answered Nov 05 '22 06:11

John Robinson Jr.


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 value of the port will be a variable - $PORT, cos Heroku dynamically generates the port.

like image 1
mayorsanmayor Avatar answered Nov 05 '22 08:11

mayorsanmayor