I''d like to read a custom config file into a hash at rails startup and have access to this hash from my controller actions. I wrote a sub to create the hash in my application controller (wrong place?) but I''m having trouble accessing the hash from my actions. I''m probably doing something silly as I''m fairly new to RoR. Thanks a lot. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ed wrote:> I''d like to read a custom config file into a hash at rails startup and > have access to this hash from my controller actions. I wrote a sub to > create the hash in my application controller (wrong place?) but I''m > having trouble accessing the hash from my actions. I''m probably doing > something silly as I''m fairly new to RoR.The application controller seems the right place to put the method to read in the data. For it to be available to all controllers in their methods, you probably want to put it into a class variable... -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
2008/3/4, Ed <pyroguy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > I''d like to read a custom config file into a hash at rails startup and > have access to this hash from my controller actions. I wrote a sub to > create the hash in my application controller (wrong place?) but I''m > having trouble accessing the hash from my actions. I''m probably doing > something silly as I''m fairly new to RoR.Assuming it''s a yaml file, completely untested: require "yaml" class ApplicationController < ActionController::Base MY_CONFIG = YAML.load(File.read(File.join(RAILS_ROOT, "config", "my_config.yml"))) end Now you can simply access MY_CONFIG from all your controllers. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---