【问题标题】:rspec failing "Missing host to link to!..."rspec 失败“缺少要链接的主机!...”
【发布时间】:2014-03-19 09:19:49
【问题描述】:

我目前收到以下错误:

 1) Organization.invite_user should create a new user for a specific orgs initial user
     Failure/Error: organization.invite_user(second_email)
     ActionView::Template::Error:
       Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
     # ./app/views/devise/mailer/reset_password_instructions.html.erb:5:in `_app_views_devise_mailer_reset_password_instructions_html_erb___4480543240081585515_70131221479860'
     # ./app/models/organization.rb:34:in `invite_user'
     # ./spec/models/organization_spec.rb:24:in `block (3 levels) in <top (required)>'

有人知道 rspec 中会发生什么吗?

【问题讨论】:

    标签: ruby-on-rails ruby rspec devise


    【解决方案1】:

    在您的 config/environments/test.rb 文件中,您应该提供以下配置:

    config.action_mailer.default_url_options = { host: 'www.example.com' }
    

    ActionMailer 生成的链接

    【讨论】:

      【解决方案2】:

      错误似乎很容易解释:您需要向邮件初始化程序提供更多信息,以便它知道如何实际呈现链接。

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

      如果您不这样做,则链接必须是亲戚,这在谈论电子邮件中的链接时毫无意义。

      【讨论】:

      • 你能举个例子说明你会如何做到这一点吗?我对 Rails 很陌生
      猜你喜欢
      • 1970-01-01
      • 2017-11-08
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      • 1970-01-01
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      相关资源
      最近更新 更多