我想做这样的事情
config.default_host = 'www.subdomain.example.com'
在我的一些配置文件中,以便 object_url
帮助程序 (ActionView::Helpers::UrlHelper
) 生成以 http://www.subdomain.example.com 开头的链接
我尝试搜索文档,但除了 ActionMailer
文档和 http://api.rubyonrails.org/classes/Rails/Configuration.html 之外,我没有找到任何内容。这对我来说没有用,因为我不知道该看哪个拍。有没有地方描述了Rails::Initializer.config的整个结构?
最佳答案
asset_host
不适用于网址
您需要在 ApplicationController
中覆盖 default_url_options
(至少在 Rails 3 中)
http://edgeguides.rubyonrails.org/action_controller_overview.html#default-url-options
class ApplicationController < ActionController::Base
def default_url_options
if Rails.env.production?
{:host => "myproduction.com"}
else
{}
end
end
end
关于ruby-on-rails - 如何在 Rails 中设置 url 助手的默认主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2660172/