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

You need to add the following line at every environment:

config.action_mailer.default_url_options = { :host => "yourhost" }

That way, it can work in all environments and could be different from environment to environment. For example:

development.rb

config.action_mailer.default_url_options = { :host => "dev.yourhost.com" }

test.rb

config.action_mailer.default_url_options = { :host => "test.yourhost.com" }

production.rb

config.action_mailer.default_url_options = { :host => "www.yourhost.com" }

Your::Application.routes.draw do
  default_url_options :host => "example.com"

  # ... snip ...
end

Somewhere in routes.rb :)


The host should be specified in each environment's config file. Eg:

config/environments/development.rb

See this question and this question.