# Code\_paths (was: Re: Rails.plugins\[:plugin\_name\] comments and patch)

**URL:** <https://www.ruby-forum.com/t/code-paths-was-re-rails-plugins-plugin-name-comments-and-patch/124265>\
**Category:** Engines Development\
**Created:** [December 27, 2007, 7:24am UTC](https://www.ruby-forum.com/t/code-paths-was-re-rails-plugins-plugin-name-comments-and-patch/124265 "2007-12-27T07:24:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [December 27, 2007, 7:24am UTC](https://www.ruby-forum.com/t/code-paths-was-re-rails-plugins-plugin-name-comments-and-patch/124265/1 "2007-12-27T07:24:34Z")

</div>

I should add… this fix (self.code\_paths instead of  
Rails[:plugin\_name].code\_paths) seemed to make it not crash and did  
store  
the path in Rails.plugins[:plugin\_name]. But, it just didn’t work. I  
eventually traced it down to the fact that rails adds plugin paths  
_before_  
engines is loaded.

/usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb ln ~60

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

```

routines,  
# in order:  
#  
# \* #check\_ruby\_version  
# \* #set\_load\_path  
# \* #require\_frameworks  
# \* #set\_autoload\_paths  
# \* add\_plugin\_load\_paths \*\*\*\*\*\*\*\*\*\* plugin code\_paths are added  
to  
Dependencies.load\_paths here  
# \* #load\_environment  
# \* #initialize\_encoding  
# \* #initialize\_database  
# \* #initialize\_logger  
# \* #initialize\_framework\_logging  
# \* #initialize\_framework\_views  
# \* #initialize\_dependency\_mechanism  
# \* #initialize\_whiny\_nils  
# \* #initialize\_temporary\_directories  
# \* #initialize\_framework\_settings  
# \* #add\_support\_load\_paths  
# \* #load\_plugins \*\*\*\*\*\*\*\*\* but plugins are loaded  
here  
# \* #load\_observers  
# \* #initialize\_routing  
# \* #after\_initialize  
# \* #load\_application\_initializers  
def process

Actually, this seems like a rails bug in itself. Or maybe it’s that way  
by  
design? In either case, it will break your code\_paths done in a  
plugin’s  
initialize. Here’s a patch for engines loader (again which doesn’t seem  
to  
really belong in engines… but it already has the loader overridden…)

vendor/plugins/engines/lib/engines/plugin/loader.rb

module Engines  
class Plugin  
class Loader \< Rails::Plugin::Loader

- 

```
 def load_plugins

```

- 

```
   super

```

- 

```
   add_plugin_load_paths

```

- 

```
 end

```

- 

```
protected
  def register_plugin_as_loaded(plugin)
    super plugin
    Engines.plugins << plugin
    register_to_routing(plugin)
  end

  # Registers the plugin's controller_paths for the routing 

```

system.  
def register\_to\_routing(plugin)  
initializer.configuration.controller\_paths +=  
plugin.select\_existing\_paths(:controller\_paths)  
initializer.configuration.controller\_paths.uniq!  
end  
end  
end  
end

-Andrew
