# Configuration search order

**URL:** <https://www.ruby-forum.com/t/configuration-search-order/98496>\
**Category:** Rails\
**Created:** [July 15, 2006, 1:52am UTC](https://www.ruby-forum.com/t/configuration-search-order/98496 "2006-07-15T01:52:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ola\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/858c86/32.png) [@Ola\_B](https://www.ruby-forum.com/u/Ola_B)\
**Post date:** [July 15, 2006, 1:52am UTC](https://www.ruby-forum.com/t/configuration-search-order/98496/1 "2006-07-15T01:52:37Z")

</div>

Hi

I’m in the process of deciding how a plugin should be designed to make  
configuration as easy as possible. Right now I require the plugin from  
init.rb, and set some configuration options (as class attribute  
accessors) from environment.rb. Then I tried setting these from  
environments/development.rb instead, and to my surprise this didn’t  
work. It said the class in question hadn’t been loaded yet. So I guess  
my question is in which order the global environment.rb, the  
environtments/$RAILS\_ENV.rb and plugins/\*/init.rb gets run… Is there  
any good way to add env-specific configuration to a plugin? Would kinda  
come in handy, actually…

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.

---

<div class="post-metadata">

**Author:** ![Ola\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/858c86/32.png) [@Ola\_B](https://www.ruby-forum.com/u/Ola_B)\
**Post date:** [July 15, 2006, 10:33am UTC](https://www.ruby-forum.com/t/configuration-search-order/98496/2 "2006-07-15T10:33:24Z")

</div>

Ezra Z. wrote:

> ```
> # * #require_frameworks
> # * #load_plugins
> # * #initialize_routing
> #
> 
> ```

Hi Ezra!

Yes, of course. I had a slight misconception about config/environment.rb  
though. As far as I can find, this file is the one who actually runs the  
Rails::Initializer. But if that’s the case, there’s no current way to  
give different plugins different configurations based on environment  
without doing a hack solution at the bottom of environment.rb.

For example, the case in point is my small authentication plugin for  
CAS. Optimally, I would set this plugin to go to another server in  
development (or even fake out the authentication completely while  
developing.) … It doesn’t seem like the rails way (or the ruby way) to  
add this at the end of environment.rb  
if ENV[‘RAILS\_ENV’] == 'development  
CAS::Filter.fake = “test\_person\_uid”  
else  
CAS::Filter.login\_url = “htt://cas.company.com/login”  
end

Maybe I’m the only one with this problem. Is there any specific rational  
behind doing load\_plugins after load\_environment?

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.

---

<div class="post-metadata">

**Author:** ![Ola\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/858c86/32.png) [@Ola\_B](https://www.ruby-forum.com/u/Ola_B)\
**Post date:** [July 15, 2006, 2:08am UTC](https://www.ruby-forum.com/t/configuration-search-order/98496/3 "2006-07-15T02:08:33Z")

</div>

On Jul 14, 2006, at 4:49 PM, Ola B. wrote:

> init.rb gets run… Is there any good way to add env-specific  
> configuration to a plugin? Would kinda come in handy, actually…
> 
> –  
> Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
> JvYAML, RbYAML, JRuby and Jatha contributor  
> System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
> OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))
> 
> “Yields falsehood when quined” yields falsehood when quined.

Ola-

```
You can look in rails/railties/lib/initializer.rb to see the order

```

in which things are loaded. Here is the relevant part:

```
 # Sequentially step through all of the available initialization

```

routines,  
# in order:  
#  
# \* #set\_load\_path  
# \* #set\_connection\_adapters  
# \* #require\_frameworks  
# \* #load\_environment  
# \* #initialize\_database  
# \* #initialize\_logger  
# \* #initialize\_framework\_logging  
# \* #initialize\_framework\_views  
# \* #initialize\_dependency\_mechanism  
# \* #initialize\_breakpoints  
# \* #initialize\_whiny\_nils  
# \* #initialize\_framework\_settings  
# \* #load\_environment  
# \* #load\_plugins  
# \* #initialize\_routing  
#  
# (Note that #load\_environment is invoked twice, once at the  
start and  
# once at the end, to support the legacy configuration style  
where the  
# environment could overwrite the defaults directly, instead of  
via the  
# Configuration instance.  
def process  
check\_ruby\_version  
set\_load\_path  
set\_connection\_adapters

```
   require_frameworks
   load_environment

   initialize_database
   initialize_logger
   initialize_framework_logging
   initialize_framework_views
   initialize_dependency_mechanism
   initialize_breakpoints
   initialize_whiny_nils
   initialize_temporary_directories

   initialize_framework_settings

   # Support for legacy configuration style where the environment
   # could overwrite anything set from the defaults/global through
   # the individual base class configurations.
   load_environment

   add_support_load_paths

   load_plugins

   # Routing must be initialized after plugins to allow the

```

former to extend the routes  
initialize\_routing

```
   # the framework is now fully initialized
   after_initialize
 end

```

Cheers-  
-Ezra
