Not being able to access the info loaded by config.yml

Hi,

I have the following app_config.yml in rails_root/config/

development: &non_production_settings
:bit_ly:
:login: “xxxxxxxxx”
:api_key: “xxxxxxxxx”
:history: “0”

test:
<<: *non_production_settings

production:
:bit_ly:APP_CONFIG = YAML.load(File.read(RAILS_ROOT +
“/config/app_config.yml”))[RAILS_ENV]
:login: “xxxxxxxxx”
:api_key: “xxxxxxxxx”
:history: “1”

i am loading this config file with following

APP_CONFIG = YAML.load(File.read(RAILS_ROOT +
“/config/app_config.yml”))[RAILS_ENV]

in my lib/somefolder/comeclass i am calling

APP_CONFIG[:bit_ly][:history] which results in an error ‘const-missing’

what can be the reason?

Am 04.01.2010 um 21:09 schrieb Quee WM:

“/config/app_config.yml”))[RAILS_ENV]

in my lib/somefolder/comeclass i am calling

APP_CONFIG[:bit_ly][:history] which results in an error ‘const-missing’

what can be the reason?

I think yaml keys need to be strings, not symbols, i.e. that would read:

development:
bit_ly:
login: something
api_key: secret
history: 0

Felix

You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

I think yaml keys need to be strings, not symbols, i.e. that would read:

development:
bit_ly:
login: something
api_key: secret
history: 0

Felix

Well I followed the info provided here:

and am able to access the data easily

the error i get for this code here:

URI.parse(“http://api.bit.ly/shorten?version=2.0.1&longUrl=” + string
+“&login=” + APP_CONFIG[:bit_ly][:login] + “&apiKey=” +
APP_CONFIG[:bit_ly][:api_key] + “&history=” +
APP_CONFIG[:bit_ly][:history] + “&format=xml”)

is

NameError: uninitialized constant CreateUrl::APP_CONFIG
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/
dependencies.rb:105:in const_missing' from /home/rails/app1/lib/mycode/create_url.rb:6:in bit_ly_for_vehicle’