Missing host to link to! Please provide the :host parameter, for Rails 4

20,385

Solution 1

For Rails 5, use:

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

You can put this in a config/environments/ file (or any other initializer), or e.g. at the beginning of config/routes.rb.

Solution 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" }

Solution 3

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

Solution 4

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

Share:
20,385
Raunak Joneja
Author by

Raunak Joneja

Updated on May 01, 2020

Comments

  • Raunak Joneja
    Raunak Joneja almost 4 years

    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.