Reputation: 10744
This is my config/initializers/tire.rb
file:
if Rails.env.production?
Tire.configure do
url "http://remoteserver.com:9200"
end
end
If I try on my production server:
bundle exec rake environment tire:import CLASS=Object FORCE=true RAILS_ENV=production
I get error:
The original exception was: #<Errno::ECONNREFUSED: Connection refused - connect(2)>
If I remove the if
sentence is working fine.
How can I to know rails environment on tire.rb file?
Upvotes: 2
Views: 1032
Reputation: 14419
A Rails initializer (config/initializers/tire.rb
) is normally a perfectly fine place for Rails configuration.
Check out the application template, or better, generate an example application with it and change it eg to:
Tire.configure do
url 'http://localhost:9201'
end
You should see it applied correctly -- when you run bundle exec rake environment tire:import:all
, you'll see Skipping index creation, cannot connect to Elasticsearch
Of course, when you want to configure Elasticsearch URL differently in development/production/etc, it's a good idea to put it into the environment configuration file. Another solution is to use the ELASTICSEARCH_URL
environment variable, which is supported by Tire out of the box, and used on Heroku, Bonsai, etc.
Upvotes: 2
Reputation: 20232
You can add the Tire initialization code to config/environments/production.rb
as opposed to checking for it in the tire.rb file (remove the tire.rb initializer when you move it)
Another thing I've done in the past is a YAML configuration file as talked about in http://railscasts.com/episodes/85-yaml-configuration-revised. Then you can just link the settings you need in the same way you do database.yml.
Upvotes: 2