Missing host to link to! Please provide the :host

2019-02-18 11:58发布

问题:

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

I randomly get this error at time, generally restarting the server fixes the issue for a while, and then it shows up again. I have added config.action_mailer.default_url_options = "localhost:3000", in the development and test.rb files.

Also, I have used include Rails.application.routes.url_helpers in one module to get access to the routes, I read this could be the reason I get these errors but removing it will leave me with no access to the routes.
The module is for the datatables gem.

回答1:

For Rails 5, use:

Rails.application.routes.default_url_options[:host] = "XXX"


回答2:

You should write in the following way

For Development(development.rb)

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

In production (production.rb)

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


回答3:

You have updated the default url options for action mailer. URL helpers will take the option from action_controller settings.

config.action_controller.default_url_options = .....

BR



回答4:

I had a similar error. The problem is in your configuration.

Try rewriting your configuration for your development.rb and test.rb like this:

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

Also check that your configuration in production.rb is written correctly like this:

config.action_mailer.default_url_options = { host: 'myherokuapp.herokuapp.com' }