Yes.
In /config/initializers
create a file called say "config.yml
" Set it up like so:
config.yml:
---
## NOT a tab character. 3 spaces. (In case that affects you)
development:
path_to_uploads: /path/to/downloads/for/development
production:
path_to_uploads: /path/to/downloads/for/production
test:
path_to_uploads: /path/to/downloads/for/test
Then create a file in the same directory (/config/initializers/
) called config.rb
config.rb:
APP_CONFIG = YAML.load_file("#{Rails.root}/config/initializers/config.yml")
Hop over to your controller:
foo_controller.rb:
class FooController < ApplicationController
def download
# ...
path_to_uploads = Rails.root.to_s + APP_CONFIG["#{Rails.env}"]['path_to_uploads']
## By handing it the Rails.env object, it will return the current environment and handle selecting the correct environment for you.
end
end
There is an excellent RailsCast on using YAML to find the environment here.
Hope that helps!