【发布时间】:2016-02-28 15:30:06
【问题描述】:
整个下午都在做这个……
我在 heroku 上设置了一个代码库多个应用程序。我正在尝试在主页(stati_controller)上显示主机,该主机适用于我的主域:www.domain.hu(env:production,production.rb)但不在另一个:www.domain.co。英国(环境:生产-英国,生产-uk.rb) 调试告诉我:无 我错过了什么?
基于this 和this 我尝试了以下但没有运气(一个接一个地尝试......)。在 production-uk.rb:
Rails.application.default_url_options[:host] = 'www.domain.co.uk'
Rails.application.default_url_options[:host] = 'domain.co.uk'
config.asset_host = 'www.domain.co.uk' - this "kills" the CSS
config.default_url_options = { host: 'www.domain.co.uk' }
config.default_url_options[:host] = 'domain.co.uk'
config.action_controller.default_url_options = { host: 'www.domain.co.uk' }
config.action_controller.default_url_options = { host: 'domain.co.uk' }
Rails.application.default_url_options = { host: 'domain.co.uk' }
config.action_controller.default_url_options = { host: 'domain.co.uk' }
config.action_controller.default_url_options[:host] = 'domain.co.uk'
host = 'www.domain.co.uk'
config.action_controller.default_url_options = { host: host }
我也在 static_pages_controller.rb 中尝试过这个 - 没有运气(有或没有前置过滤器):
def default_url_options
if Rails.env == 'production'
{:host => "www.domain.hu"}
elsif Rails.env == 'production-uk'
{:host => "www.domain.co.uk"}
else
{}
end
end
并且根据 request.host 验证作品很好,所以我不明白 (static_pages_controller.rb):
before_filter :authenticate
...
def authenticate
domain = request.host
if domain == 'www.domain.hu'
authenticate_or_request_with_http_basic do |username, password| username == 'stuff' && password == 'boda'
end
elsif domain == 'www.domain.co.uk'
authenticate_or_request_with_http_basic do |username, password| username == 'stuff' && password == 'boda'
end
end
end
我在 production-uk.rb 中也有这个,它也有效:
host = 'www.domain.co.uk'
config.action_mailer.default_url_options = { host: host }
更新 还有一件事:当我在应用程序的 heroku 控制台中编写 app.host 时,回复始终是“www.example.com”
感谢阅读!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 heroku environment host