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

有些话、适合烂在心里 提交于 2019-12-31 10:04:10

问题


My ruby on rails action mailer runs all good in development environment, but in production environment, it keeps throw:

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

My development config is

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :port           => xxx,
  :address        => 'smtp.example.org',
  :user_name      => 'xxx@example.com',
  :password       => 'xxxxxxxx',
  :domain         => 'xxxxxx.com',
  :authentication => :plain,
}

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

My production config is

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :port           => 587,
  :address        => 'smtp.example.org',
  :user_name      => 'xxx@example.com',
  :password       => 'xxxxxx',
  :domain         => 'example.com',
  :authentication => :plain,
}
config.action_mailer.default_url_options = { :host => 'example.com' }

My other environments are:

ruby 2.1.1
rails 4.0.3
sidekiq 
devise
devise-async

I have tried:

  1. Add the following in a initializer file

    ActionMailer::Base.default_url_options[:host] = "example.com"
    
  2. This answer here

Neither of them works.


回答1:


In the end I added the following with the correct value to each environment file:

test.rb / development.rb / production.rb

Devise 3.2.x - 4.x.x

Rails 4.1.x && Rails 4.2.x && Rails 5.x.x

Thanks to maudulus

# Default Mailer Host
  Rails.application.routes.default_url_options[:host] = 'domain.com'



回答2:


Try restarting the server. Even in Rails 4.1 the config is not reparsed without a restart.



来源:https://stackoverflow.com/questions/22288951/actionviewtemplateerror-missing-host-to-link-to-please-provide-the-host-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!