Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load configuration at startup in rails?

I have some configuration values in a YAML file that needs loaded when my app starts up. The values need to be accessed in a few different places (both in a few models and a few controllers). What is the best way to load, store, and access these?

like image 816
NotDan Avatar asked Oct 23 '10 16:10

NotDan


2 Answers

You can do as follows

create file yml example test.yml :

key: 936QQ84d3c4m8Y4Y

create file in config/initializers.

test = YAML.load_file("#{RAILS_ROOT}/config/test.yml")
KEY = test["key"]
like image 66
khanh Avatar answered Nov 09 '22 23:11

khanh


An initializer. John Nunemaker posted the one he uses for Harmony over on gist.

So in that example harmony.rb would go in config/initializers and harmony.yml would just be in config.

like image 37
Robert Speicher Avatar answered Nov 09 '22 23:11

Robert Speicher