# How to access Rails::Configuration instance methods

**URL:** <https://www.ruby-forum.com/t/how-to-access-rails-configuration-instance-methods/138271>\
**Category:** Rails\
**Created:** [May 21, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/how-to-access-rails-configuration-instance-methods/138271 "2008-05-21T15:56:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubyfreak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubyfreak](https://www.ruby-forum.com/u/rubyfreak)\
**Post date:** [May 21, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/how-to-access-rails-configuration-instance-methods/138271/1 "2008-05-21T15:56:48Z")

</div>

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\_path  
> > NoMethodError: 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.

---

<div class="post-metadata">

**Author:** ![rubyfreak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubyfreak](https://www.ruby-forum.com/u/rubyfreak)\
**Post date:** [May 21, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/how-to-access-rails-configuration-instance-methods/138271/2 "2008-05-21T16:14:32Z")

</div>

On 21 May 2008, at 14:55, Ruby F. wrote:

> > > 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

---

<div class="post-metadata">

**Author:** ![rubyfreak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubyfreak](https://www.ruby-forum.com/u/rubyfreak)\
**Post date:** [May 21, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/how-to-access-rails-configuration-instance-methods/138271/3 "2008-05-21T16:24:09Z")

</div>

On May 21, 10:13 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

---

<div class="post-metadata">

**Author:** ![rubyfreak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubyfreak](https://www.ruby-forum.com/u/rubyfreak)\
**Post date:** [May 21, 2008, 5:17pm UTC](https://www.ruby-forum.com/t/how-to-access-rails-configuration-instance-methods/138271/4 "2008-05-21T17:17:18Z")

</div>

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.
