ActionView::Template::错误:缺少要链接的主机!请提供 :host 参数,设置 default_url_options[:host],或设置 :only_path 为 true

2024-02-20

我的 ruby​​ on Rails 动作邮件程序在开发环境中运行良好,但在生产环境中,它不断抛出:

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

我的开发配置是

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :port           => xxx,
  :address        => 'smtp.example.org',
  :user_name      => '[email protected] /cdn-cgi/l/email-protection',
  :password       => 'xxxxxxxx',
  :domain         => 'xxxxxx.example',
  :authentication => :plain,
}

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

我的生产配置是

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :port           => 587,
  :address        => 'smtp.example.org',
  :user_name      => '[email protected] /cdn-cgi/l/email-protection',
  :password       => 'xxxxxx',
  :domain         => 'example.com',
  :authentication => :plain,
}
config.action_mailer.default_url_options = { :host => 'example.com' }

我的其他环境是:

ruby 2.1.1
rails 4.0.3
sidekiq
devise
devise-async

我努力了:

  1. 在初始化文件中添加以下内容

    ActionMailer::Base.default_url_options[:host] = "example.com"
    
  2. 这个答案here https://stackoverflow.com/a/7219803

它们都不起作用。


最后,我向每个环境文件添加了以下具有正确值的内容:

test.rb / development.rb / production.rb

设计 3.2.x - 4.x.x

导轨 4.1.x&&导轨 4.2.x&&Rails 5.x.x

谢谢maudulus https://stackoverflow.com/a/23208572/737275

# Default Mailer Host
  Rails.application.routes.default_url_options[:host] = 'domain.example'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ActionView::Template::错误:缺少要链接的主机!请提供 :host 参数,设置 default_url_options[:host],或设置 :only_path 为 true 的相关文章

随机推荐