I am using a gem (RTURK) and right now I have the following code on the class that wraps the gem:
if Rails.env.production?
RTurk.setup(ENV['AMAZON_KEY_ID'], ENV['AMAZON_KEY'], :sandbox => false)
else
RTurk.setup(ENV['AMAZON_KEY_ID'], ENV['AMAZON_KEY'], :sandbox => true)
end
I want to move that to a configuration/environments/production and configuration/environments/development and test
But I am unsure at which point I should place the configuration of the gem. Does it need to be in a config.after_initialize
?
The environment files are loaded before any initializers (see Rails Initalization Guide). This means that you can set a configuration variable in your environment file, and then use it in an initializer.
In your case, it looks like the only thing that differs is whether or not RTurk will be sandboxed. You can add config.rturk_sandbox = true
to application.rb, and config.rturk_sandbox = false
to production.rb file. Then create config/initializers/rturk.rb, which uses that value.
RTurk.setup(ENV['AMAZON_KEY_ID'], ENV['AMAZON_KEY'], :sandbox => YourApp::Application.config.rturk_sandbox)
(I'm suggesting adding config.rturk_sandbox = true
to application.rb so that it does the safe thing if you forget to set that in an individual environment file.)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments