Rails:缺少要链接的主机!请提供 :host 参数或设置 default_url_options[:host] [英] Rails: Missing host to link to! Please provide :host parameter or set default_url_options[:host]
问题描述
我已经在谷歌上搜索了大约 90 分钟,但仍然没有答案.我在哪里设置 default_url_options
?我已经为 config.action_mailer.default_url_options
设置它以解决其他地方的相同错误,但现在我在 RSpec 规范中尝试使用 URL 帮助程序时遇到此错误.我不知道它期望在哪里设置 default_url_options.
I have been googling for about 90 minutes now and still don't have an answer to this. Where do I set default_url_options
? I've already set it for config.action_mailer.default_url_options
to solve this same bug elsewhere, but now I'm getting this error when trying to use a URL helper inside an RSpec spec. I have no idea where it's expecting default_url_options to be set.
Failure/Error: listing_url(listing).should match(/\/\d+-\w+$/)
RuntimeError:
Missing host to link to! Please provide :host parameter or set default_url_options[:host]
# ./spec/routing/listing_routing_spec.rb:9:in `block (3 levels) in <top (required)>'
这段代码与 emails/ActionMailer 无关,只是碰巧需要一个 URL 而不是路径.
This code has nothing to do with emails/ActionMailer, it just happens to need a URL instead of a path.
有什么想法吗?
推荐答案
Your::Application.routes.draw do
default_url_options :host => "example.com"
# ... snip ...
end
routes.rb
中的某处:)
这篇关于Rails:缺少要链接的主机!请提供 :host 参数或设置 default_url_options[:host]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!