views:

43

answers:

2

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?

+2  A: 

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.

rspeicher
+1  A: 

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"]
Nam Khanh