How do I set default host for url helpers in rails

2020-01-24 08:00发布

I would like to do something like this

config.default_host = 'www.subdomain.example.com'

in some of my configuration files, so that object_url helpers (ActionView::Helpers::UrlHelper) produce links beginning with http://www.subdomain.example.com

I have tried to search the docs but I did not find anything except ActionMailer docs and http://api.rubyonrails.org/classes/Rails/Configuration.html which is not useful for me, because I do not know in which pat to look. Is there a place which describes the whole structure of Rails::Initializer.config?

8条回答
不美不萌又怎样
2楼-- · 2020-01-24 08:28

There's this, but I'm not terribly sure if they're the helpers you're referring to:

ActionController::Base.asset_host = "assets.example.com"

http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html

查看更多
ゆ 、 Hurt°
3楼-- · 2020-01-24 08:29

Another way is to set it like this

# config/production.rb
config.action_controller.default_url_options = { host: 'myproduction.com' }
查看更多
登录 后发表回答