David Kahn
2011-May-10 17:31 UTC
Why is deep_symbolize_keys not available within application.rb (undefined method `deep_symbolize_keys'' for Hash)
If there is a better way to do this I am open: I am trying to load a yaml config file which holds application settings (which happens to be shared between the main app and an engine). class Application < Rails::Application config_file = "#{Rails.root}/config/config.yml" if File.exists?(config_file) ::APP_CONFIG YAML.load_file(config_file)[Rails.env].deep_symbolize_keys else puts "No config.yml file found, run ''rails g blog_engine:install''" end .... end The file loads if I use #symbolize_keys, but Hash#deep_symbolize_keys is not available at this point. I know I could iterate the hash myself and do this but of course would prefer not to and makes me wonder if there is an alternative way to load such a config file and have the values accessible within environment.rb so that I can assign the value. Thanks, David -- 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.
David Kahn
2011-May-10 17:37 UTC
Re: Why is deep_symbolize_keys not available within application.rb (undefined method `deep_symbolize_keys'' for Hash)
Ok, so it looks like I need ActiveSupport::CoreExtensions::Hash. A bit confused as at the top of application.rb there is * require ''rails/all'' *, so I would think this should be included but is not. ActiveSupport is loaded but not CoreExtensions. ActiveSupport::CoreExtensions::Hash::Conversions<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Conversions>, ActiveSupport::CoreExtensions::Hash::DeepMerge<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/DeepMerge>, ActiveSupport::CoreExtensions::Hash::Diff<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Diff>, ActiveSupport::CoreExtensions::Hash::Except<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Except>, ActiveSupport::CoreExtensions::Hash::IndifferentAccess<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/IndifferentAccess>, ActiveSupport::CoreExtensions::Hash::Keys<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Keys>, ActiveSupport::CoreExtensions::Hash::ReverseMerge<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/ReverseMerge>, ActiveSupport::CoreExtensions::Hash::Slice<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Slice> On Tue, May 10, 2011 at 12:31 PM, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org>wrote:> If there is a better way to do this I am open: I am trying to load a yaml > config file which holds application settings (which happens to be shared > between the main app and an engine). > > class Application < Rails::Application > config_file = "#{Rails.root}/config/config.yml" > if File.exists?(config_file) > ::APP_CONFIG > YAML.load_file(config_file)[Rails.env].deep_symbolize_keys > else > puts "No config.yml file found, run ''rails g blog_engine:install''" > end > .... > end > > The file loads if I use #symbolize_keys, but Hash#deep_symbolize_keys is > not available at this point. I know I could iterate the hash myself and do > this but of course would prefer not to and makes me wonder if there is an > alternative way to load such a config file and have the values accessible > within environment.rb so that I can assign the value. > > Thanks, > > David >-- 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.
David Kahn
2011-May-10 17:43 UTC
Re: Why is deep_symbolize_keys not available within application.rb (undefined method `deep_symbolize_keys'' for Hash)
On Tue, May 10, 2011 at 12:37 PM, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org>wrote:> Ok, so it looks like I need ActiveSupport::CoreExtensions::Hash. A bit > confused as at the top of application.rb there is * require ''rails/all'' *, > so I would think this should be included but is not. ActiveSupport is loaded > but not CoreExtensions. > ActiveSupport::CoreExtensions::Hash::Conversions<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Conversions>, > ActiveSupport::CoreExtensions::Hash::DeepMerge<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/DeepMerge>, > ActiveSupport::CoreExtensions::Hash::Diff<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Diff>, > ActiveSupport::CoreExtensions::Hash::Except<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Except>, > ActiveSupport::CoreExtensions::Hash::IndifferentAccess<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/IndifferentAccess>, > ActiveSupport::CoreExtensions::Hash::Keys<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Keys>, > ActiveSupport::CoreExtensions::Hash::ReverseMerge<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/ReverseMerge>, > ActiveSupport::CoreExtensions::Hash::Slice<http://rubydoc.info/docs/rails/2.3.8/ActiveSupport/CoreExtensions/Hash/Slice>Looks like I have answered my own question: if I do my assignments in "config.after_initialize" then I have the CoreExtensions and deep_symbolize_keys.> > > On Tue, May 10, 2011 at 12:31 PM, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org>wrote: > >> If there is a better way to do this I am open: I am trying to load a yaml >> config file which holds application settings (which happens to be shared >> between the main app and an engine). >> >> class Application < Rails::Application >> config_file = "#{Rails.root}/config/config.yml" >> if File.exists?(config_file) >> ::APP_CONFIG >> YAML.load_file(config_file)[Rails.env].deep_symbolize_keys >> else >> puts "No config.yml file found, run ''rails g blog_engine:install''" >> end >> .... >> end >> >> The file loads if I use #symbolize_keys, but Hash#deep_symbolize_keys is >> not available at this point. I know I could iterate the hash myself and do >> this but of course would prefer not to and makes me wonder if there is an >> alternative way to load such a config file and have the values accessible >> within environment.rb so that I can assign the value. >> >> Thanks, >> >> David >> > >-- 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.
Sean Linsley
2012-Nov-30 03:46 UTC
Re: Why is deep_symbolize_keys not available within application.rb (undefined method `deep_symbolize_keys'' for Hash)
On Tuesday, May 10, 2011 12:43:16 PM UTC-5, David Kahn wrote:> On Tue, May 10, 2011 at 12:37 PM, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org<javascript:> > > wrote: > >> Ok, so it looks like I need ActiveSupport::CoreExtensions::Hash. A bit >> confused as at the top of application.rb there is * require ''rails/all'' *, >> so I would think this should be included but is not. ActiveSupport is >> loaded but not CoreExtensions. > > > Looks like I have answered my own question: if I do my assignments in > "config.after_initialize" then I have the CoreExtensions and > deep_symbolize_keys. >Your workaround didn''t work for me, as I want to use my config hash in application.rb directly. A quick recursive grep through all of my gems located the offender: i18n, of all things. While ActiveSupport has Hash.deep_symbolize_keys defined on the master branch on Github, that hasn''t made into the latest release (3.2.9). So for now, require ''i18n/core_ext/hash'' will do the job nicely. -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/PuF_tjNyCMEJ. For more options, visit https://groups.google.com/groups/opt_out.