There was a thread yesterday about ENV["_"] which is not available to Windows, I got to playing around with how to find access to the initializer_path or in this case the root_path My question is more about why I don''t have access to what appears to be a public method than finding the root_path. I did this in 2.0.2 with script/console The Rails object has a Configuration class accessible via Rails::Configuration I have script console running and at the same time I am starring at the code to initializer.rb In initializer.rb is a class named Configuration. It has an accessor to :root_path class Configuration # The application''s base directory. attr_reader :root_path yet when I try to access this I get an undefined method error.>> puts Rails::Configuration.root_pathNoMethodError: undefined method `root_path'' for Rails::Configuration:Class from (irb):122 if I list the instance methods, root_path is listed, yet it is not listed under Rails::Configuration.public_methods. Is Configuration a singleton class? How do I access root_path or any of the other instance methods? Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-21 14:13 UTC
Re: How to access Rails::Configuration instance methods
On 21 May 2008, at 14:55, Ruby Freak wrote:> > > In initializer.rb is a class named Configuration. It has an accessor > to :root_path > > class Configuration > # The application''s base directory. > attr_reader :root_path > > yet when I try to access this I get an undefined method error. > >>> puts Rails::Configuration.root_path > NoMethodError: undefined method `root_path'' for > Rails::Configuration:Class > from (irb):122 >Well yes, you''re trying to call an instance method but you''re calling it on the class, not on an instance of it. I don''t think that instance is kept around in any accessible form after the boot process, although I suppose you could stash it in a constant in environment.rb. Why would you want to ? Fred> if I list the instance methods, root_path is listed, yet it is not > listed under > Rails::Configuration.public_methods. > > Is Configuration a singleton class? > > How do I access root_path or any of the other instance methods? > > Thanks in advance. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Clever Neologism
2008-May-21 14:23 UTC
Re: How to access Rails::Configuration instance methods
On May 21, 10:13 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Well yes, you''re trying to call an instance method but you''re calling > it on the class, not on an instance of it. > I don''t think that instance is kept around in any accessible form > after the boot process, although I suppose you could stash it in a > constant in environment.rb. Why would you want to ?I have always wanted to use that for site-wide configurations for plugins (similar to how you store the SMTP configuration for ActionMailer) in that configuration, but alas it seems to be not accessible to do that. My ideas for things to include there are Amazon S3 logins, e-commerce tokens and logins, etc. It just seems to not be well suited for it (and not meant for it either). I know you can put plain old constants there, but it would seem to be cleaner to use some sort of configuration setup than just the equivalent of "Here''s a global variable" in environment.rb. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, I guess I really don''t need to do it so much as I a curious about how it all works. The only real purpose is that the plugin in question was looking for the initializer_path (dunno why) and that doesn''t appear to be available through ENV["_"] in a Windows environment. Rails provides public access to the Rails.preinitializer_path, so it stands to reason that things like Rails.root_path and initializer_path etc might be handy at some point. I think I will see about adding them to my Rails object as a pedantic exercise. On May 21, 7:23 am, Clever Neologism <gest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 21, 10:13 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > Well yes, you''re trying to call an instance method but you''re calling > > it on the class, not on an instance of it. > > I don''t think that instance is kept around in any accessible form > > after the boot process, although I suppose you could stash it in a > > constant in environment.rb. Why would you want to ? > > I have always wanted to use that for site-wide configurations for > plugins (similar to how you store the SMTP configuration for > ActionMailer) in that configuration, but alas it seems to be not > accessible to do that. My ideas for things to include there are > Amazon S3 logins, e-commerce tokens and logins, etc. It just seems to > not be well suited for it (and not meant for it either). I know you > can put plain old constants there, but it would seem to be cleaner to > use some sort of configuration setup than just the equivalent of > "Here''s a global variable" in environment.rb.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---