# Rails.plugins\[:plugin\_name\] comments and patch

**URL:** <https://www.ruby-forum.com/t/rails-plugins-plugin-name-comments-and-patch/124263>\
**Category:** Engines Development\
**Created:** [December 27, 2007, 6:08am UTC](https://www.ruby-forum.com/t/rails-plugins-plugin-name-comments-and-patch/124263 "2007-12-27T06:08:01Z")\
**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, 6:08am UTC](https://www.ruby-forum.com/t/rails-plugins-plugin-name-comments-and-patch/124263/1 "2007-12-27T06:08:01Z")

</div>

Hi all,

I have some code in a plugin’s init.rb that used  
Rails.plugins[:plugin\_name].code\_paths  
+= … I spent a bit of time hacking engines to get it working, then I  
read  
Sven’s helpful message at  
[Engines 2ish / Rails 2.0.1 - Engines Development - Ruby-Forum](http://www.ruby-forum.com/topic/135196#602078)(essentially “Contrary to  
Rails  
1.2.x the init.rb file is now evalutated inside of the Plugin object.”  
and  
just use code\_paths += …)

Btw, I had to use self.code\_paths +=, not code\_paths by itself. Is that  
expected?

> “Hmm, we probably should put that into some kind of upgrade note. Or even  
> a rake task that goes through the init.rb files and removes those bits  
> like  
> Rails.Engines[:name]? But maybe that’s not worth the hassle?”

Yes definitely a message on how to migrate from 1.2.x to 2.x engines.  
The  
rake tast is probably not necessary imo, we are used to reading the  
messages  
and making appropriate changes.

Anyways I thought I would include my changes in case someone finds them  
useful. Definitely changing Rails.plugins[:plugin\_name] to self is the  
better way. But maybe someone will need to use this way for some  
reason.

-Andrew

[http://svn.rails-engines.org/engines/trunk/lib/engines/plugin.rb](http://svn.rails-engines.org/engines/trunk/lib/engines/plugin.rb)

```
# Extends the superclass' load method to additionally mirror public

```

assets  
def load(initializer)  
return if loaded?  
+

- 

```
 # add plugin before calling initializer and anything else since 

```

this  
seems

- 

```
 # to be the expected behavior

```

- 

```
 Engines.plugins << self

```

- 

```
super initializer
add_plugin_view_paths
Assets.mirror_files_for(self)

```

end

[http://svn.rails-engines.org/engines/trunk/lib/engines/plugin/loader.rb](http://svn.rails-engines.org/engines/trunk/lib/engines/plugin/loader.rb)

```
    def register_plugin_as_loaded(plugin)
      super plugin

```

- 

```
    Engines.plugins << plugin
    register_to_routing(plugin)
  end

```
