这是我的config/initializers/tire.rb文件:
if Rails.env.production?
Tire.configure do
url "http://remoteserver.com:9200"
end
end如果我在生产服务器上试用:
bundle exec rake environment tire:import CLASS=Object FORCE=true RAILS_ENV=production我得到了错误:
The original exception was: #<Errno::ECONNREFUSED: Connection refused - connect(2)>如果我删除了if语句,就可以正常工作了。
如何了解tire.rb文件上的rails环境?
发布于 2013-04-08 16:21:02
您可以将轮胎初始化代码添加到config/environments/production.rb中,而不是在tire.rb文件中检查它(移动它时删除tire.rb初始化程序)。
我过去做过的另一件事是YAML配置文件,就像在http://railscasts.com/episodes/85-yaml-configuration-revised中提到的那样。然后,您可以用database.yml的方式链接所需的设置。
发布于 2013-04-09 11:15:30
Rails初始化器(config/initializers/tire.rb)通常是Rails配置的完美位置。
查看应用程序模板,或者更好地使用它生成一个示例应用程序,并将其更改为:
Tire.configure do
url 'http://localhost:9201'
end您应该看到它被正确地应用--当您运行bundle exec rake environment tire:import:all时,您将看到Skipping index creation, cannot connect to Elasticsearch
当然,当您想要在开发/生产/其他方面以不同的方式配置Elasticsearch时,最好将其放入环境配置文件中。另一种解决方案是使用ELASTICSEARCH_URL环境变量,这是由轮胎支持的开箱即用,并使用在Heroku,盆景等。
https://stackoverflow.com/questions/15880693
复制相似问题