ActionView::Template::Error: 缺少要链接的主机!请提供:host 参数,设置default_url_options[:host],或设置:only_path 为true [英] ActionView::Template::Error: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

查看:39
本文介绍了ActionView::Template::Error: 缺少要链接的主机!请提供:host 参数,设置default_url_options[:host],或设置:only_path 为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 ruby​​ on rails action mailer 在开发环境中运行良好,但在生产环境中,它不断抛出:

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

我的开发配置是

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

我的生产配置是

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

我的其他环境是:

ruby 2.1.1
rails 4.0.3
sidekiq 
devise
devise-async

我试过了:

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

  1. Add the following in a initializer file

ActionMailer::Base.default_url_options[:host] = "example.com"

  • 这个答案这里

    它们都不起作用.

    推荐答案

    最后我在每个环境文件中添加了以下正确的值:

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

    test.rb/development.rb/production.rb

    设计 3.2.x - 4.x.x

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

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

    感谢 maudulus

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

    这篇关于ActionView::Template::Error: 缺少要链接的主机!请提供:host 参数,设置default_url_options[:host],或设置:only_path 为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆