rails4多站点显示主机 - 有时可以工作 [英] rails4 multisite show host in view - sometimes works
问题描述
我已经在这个整个下午工作了......
我在heroku上有一个codebase多个应用程序设置。我试图在主域名(stati_controller)上显示主机:www.domain.hu(env:production,production.rb),但不在另一个主域上:www.domain.co。 uk(env:production-uk,production-uk.rb)
Debug告诉我:无
我错过了什么?
基于< a href =https://stackoverflow.com/questions/2660172/how-do-i-set-default-host-for-url-helpers-in-rails>这个和这我尝试了以下但没有运气(一个接一个地尝试......)。在 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' - 这个杀死 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
如果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:验证
...
def验证
domain = request.host
if domain =='www.domain。 hu'
authenticate_or_request_with_http_basic do |用户名,密码|用户名=='东西'&&密码=='boda'
结束
elsif域=='www.domain.co.uk'
authenticate_or_request_with_http_basic do |用户名,密码|用户名=='东西'&&密码=='boda'
结束
结束
结束
我在production-uk.rb中也有这样的作品:
host ='www.domain.co.uk'
config.action_mailer.default_url_options = {host:host}
更新
还有一件事:当我在应用程序的heroku控制台中写入app.host时,答复始终为www.example.com。
感谢您阅读!
这是一个严峻的错误。我有
@host = request.host
在static_pages_controller.rb中的gmaps4rails的位中
这就是为什么它不总是工作.... grr p>
Have been working on this all afternoon now...
I have a one codebase multiple apps setup on heroku. I am trying to display the host on the home page (stati_controller) which works on my main domain: www.domain.hu (env: production, production.rb) but doesn't on the other one: www.domain.co.uk (env: production-uk, production-uk.rb) Debug tells me: nil What am I missing?
Based on this and this I tried the followings but no luck (tried one-by-one...). In 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 }
I also tried this in static_pages_controller.rb - no luck (with or without before-filter):
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
And authenticate works based on request.host fine so I don't understand (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
I have this in production-uk.rb too that works:
host = 'www.domain.co.uk'
config.action_mailer.default_url_options = { host: host }
UPDATE There is one more thing: When I am in the heroku console of the app and write app.host the reply is always "www.example.com"
Thanks for reading!
It was a stvpid mistake. I had
@host = request.host
inside the gmaps4rails's bit in the static_pages_controller.rb
That's why it didn't always work.... grr
这篇关于rails4多站点显示主机 - 有时可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!