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? -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Felix Schäfer
2010-Jan-04 20:21 UTC
Re: not being able to access the info loaded by config.yml
Am 04.01.2010 um 21:09 schrieb Quee WM:> 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?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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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 > > FelixWell I followed the info provided here: http://blog.innovativethought.net/2009/01/02/making-configuration-files-with-yaml-revised/ 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'' -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.