views:

39

answers:

1

Is it possible to define custom configuration in config/environments/*.rb or config/environment.rb file.

Is yes, how do i access them from my code (controller, model, library, helper)

Thanks.

A: 

I just use constants. Eg

AWS_PW = "ssss"

you can have different values in the different config files

Access them by their name. They're constants. They're available everywhere--controllers, views, models, etc

# eg
user.pw = AWS_PW

ADDED

Constants need to start with an upper case letter. Usual practice is to use all upper case, underscores, numerals, etc.

You need to restart Rails to pick up the new changes to the environment files since the appropriate environment file is read once.

Note: you can declare a hash as a constant. Eg

# in an environment file...
PARAMS = {}
PARAMS['default_pw'] = 'topsecret!'
Larry K
thanks, so I noticed 2 things, that they need to be upper case? and you have to restart mongrel if you change the property, even though I am in dev mode?? Is that true??
sorry i m new to ruby, just read that constant have to start with upper case. Thanks.
I updated my answer to cover your comments.
Larry K
thanks much appreciated