setting custom variables per environment


I'd like to be able to set a variable for each environment I have.
It's a path to a folder that's different on each system: development
and production. I then, need to be able to read it from my controller.

How can I do this?

You can set it in application_controller.rb like this

    when 'production' : var = 'foo'
    when 'development' : var = 'bar'

eggie5 wrote:

One slight mistake, thats controllers/application.rb not

William Pratt wrote:

I put the exact code you wrote in my controllers/application.rb file,
then tried to access var on my other controller and it won't work.: "***** var is : #{var}"

undefined local variable or method `var' for #<PrivateController:

sorry, I should have been more specific:

    case ENV['RAILS_ENV']
when 'production' : @var = 'foo'
when 'development' : @var = 'bar'

You need to make the variable an instance variable. Sorry, long day and
I was getting lazy.

eggie5 wrote:

Sorry, I am really not paying attention…if you want to access this
from another controller other than ApplicationController, you need to
make it a class variable like @@var.

William Pratt wrote:

Will I be able to access this form a model?

Will I be able to access this form a model?


You could create a constant instead of a instance/class var by adding this
into your config/environments/development.rb:

SOME_VAR = "foo"

Then in production.rb do the same, but set it to something else.

what does the .freeze do?