Heroku/devise - Missing host to link to! Please provide :host parameter or set default_url_options[:host]

benoitr picture benoitr · Nov 6, 2010 · Viewed 90.2k times · Source

I am trying to push my app on heroku. I am still in dev. I use devise with the confirmable module.

When I try to add a user with the heroku console I got this error:

Missing host to link to! Please provide :host parameter or set default_url_options[:host]

in test and dev environment i have the following line:

environments/development.rb and environments/test.rb

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

I don't have set up something in the production environment.

I've tried to push with

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

but it doesn't work too..

I see on the web that it could be related to ActionMailer but I don't know what I have to configure. Many thanks for your idea!

EDITED:

Hi,

In order to not make my app crashes when I push on heroku I put this in my env/test.rb and my env/dev.rb (not in env.rb I think it is because it's a rails 3 app)

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

But when I tried to create a user in the heroku console:

User.create(:username => "test", :email => "[email protected]", :password => "test1234", :password_confirmation => "test1234", :confirmed_at => "2010-11-03 14:11:15.520128")

here are errors I got:

ActionView::Template::Error: Missing host to link to! Please provide :host parameter or set default_url_options[:host]
/home/slugs/.../mnt/.bundle/gems/ruby/1.8/gems/actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:473:in `url_for'
/home/slugs/.../mnt/.bundle/gems/ruby/1.8/gems/actionpack-3.0.0/lib/action_dispatch/routing/url_for.rb:132:in `url_for'
/home/slugs/.../mnt/.bundle/gems/ruby/1.8/gems/actionpack-3.0.0/lib/action_view/helpers/url_helper.rb:99:in `url_for'
/home/slugs/.../mnt/.bundle/gems/ruby/1.8/gems/actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:195:in `user_confirmation_url'

EDITED (2)

When I type heroku logs on console I got this ==> production.log <== So I think when one deploys on heroku it's already in production.

I configure the env/prod.rb like this:

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

and now I have this as error when I try to create a User:

Errno::EAFNOSUPPORT: Address family not supported by protocol - socket(2)
/usr/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:551:in `initialize'
/usr/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:551:in `open'
/usr/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
/usr/ruby1.8.7/lib/ruby/1.8/timeout.rb:62:in `timeout'

Answer

thenengah picture thenengah · Nov 6, 2010

You need to add this to your environment.rb

  config.action_mailer.default_url_options = { :host => 'localhost' }

Make sure you change host to your production url and keep it localhost for development. This is for the mailer, it needs a default email to send out notices such as confirmations etc...


You should check the logs on the heroku server heroku logs run that from the console and it will tell you the exact error.

When you push to heroku you need to configure the environment.rb file with the heroku subdomain:

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

Depending upon version, this should go in production.rb, not environment.rb.