# Initializer method override

**URL:** <https://www.ruby-forum.com/t/initializer-method-override/86216>\
**Category:** Engines Development\
**Created:** [February 20, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/initializer-method-override/86216 "2007-02-20T19:25:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hugo\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@Hugo\_L](https://www.ruby-forum.com/u/Hugo_L)\
**Post date:** [February 20, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/initializer-method-override/86216/1 "2007-02-20T19:25:36Z")

</div>

Hi guys,

I am a member of Steve’s team (he posted last month about the 1.2  
branch).

1st Thanks for the amazing work to James! Engines is an amazing piece  
of  
work.

To the question then:

I would need to be able to override a Rails Initializer method  
(find\_plugins).  
I noticed that the rails\_initializer.rb file contains the  
Engine::RailsExtensions::RailsInitializer which, according to its  
leading  
comment, attempts to override 3 Initializer methods.

I therefore tried to put my “modified” version of find\_plugins using the  
conventions found in the Engine::RailsExtensions::RailsInitializer:

1. using ‘alias\_method chain’ : find\_plugins, :engine\_additions

2. writing a method called ‘find\_plugins\_with\_engine\_additions’ with a  
slightly modified body.

The problem is that it doesn’t seem to be invoked at any time (neither  
does  
the 'load\_plugin\_with\_engine\_addition).

Could you let me know how and where it should be invoked / included to  
overwrite this Initializer method

Thanks!

---

<div class="post-metadata">

**Author:** ![Hugo\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@Hugo\_L](https://www.ruby-forum.com/u/Hugo_L)\
**Post date:** [February 21, 2007, 10:56am UTC](https://www.ruby-forum.com/t/initializer-method-override/86216/2 "2007-02-21T10:56:13Z")

</div>

Hi Hugo,

Using alias\_method\_chain is normally quite easy, but if you’re doing  
it from within a module you need to be sure that the  
“alias\_method\_chain” call is made on the base class when it’s included

- see the top of  
engines/lib/engines/rails\_extensions/rails\_initializer.rb for an  
example - I’m using base.class\_eval to make the calls to  
alias\_method\_chain as if they were in the including class itself.

My guess is that it’s something like this which is stopping your  
methods being called - have a play around and if you’re still not  
making any progress, email us the code and we’ll take a look.

Cheers and thanks for the nice comments 🙂

James

---

<div class="post-metadata">

**Author:** ![Hugo\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@Hugo\_L](https://www.ruby-forum.com/u/Hugo_L)\
**Post date:** [February 22, 2007, 1:33am UTC](https://www.ruby-forum.com/t/initializer-method-override/86216/3 "2007-02-22T01:33:15Z")

</div>

Hey James,

Thanks for the tips.

Actually my problem was resolved using a combination of  
alias\_method\_chain  
and config.plugin = [“engine”, “\*”].

I ran into another small problem …

Trying to use another application that I built as a plugin, I found that  
the  
stylesheets don’t get loaded.

I tried to invoke them using \<%= "engine\_stylesheet ‘stylesheet’ %\> but  
that  
returns an error saying that engine\_stylesheet is undefined…

Any clues?

Thanks

Hugo

---

<div class="post-metadata">

**Author:** ![Hugo\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@Hugo\_L](https://www.ruby-forum.com/u/Hugo_L)\
**Post date:** [February 22, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/initializer-method-override/86216/4 "2007-02-22T21:04:42Z")

</div>

Thanks James,

the :plugin =\> “my\_plugin” did it.

Another quick question.

I am running into an issue with my CSSs which are refering to images…  
obviously when the plugin gets loaded the CSS image URL doesn’t hold any  
longer.

I figured using RCSS might help fix this (since I can use the  
image\_tab=“image”, plugin =\> “plugin” notation to refer to images) BUT  
the  
some of the RCSS techiques I’ve looked at use a special route:

map.connect ‘rcss/:rcss.:format’, :controller =\> ‘rcss’, :action =\>  
‘dispatch’

So putting this route in a stand alone app works fine, but once I try to  
refer to rcss files located in the view/rcss folder of my plugin all  
hell  
breaks loose.

The comment by the technique author is that this route statement should  
go  
before the default routes in the app’s route.rb

What I tried:

1. route in app’s route.rb (complains that controller is not found)
2. route and controller in main app (complains view isn’t there)
3. route.rb in root of plugin (no special route loaded)
4. added the map.from\_plugin :my\_plugin in the main app’s route.rb (no  
special route loaded)

Thanks James!

---

<div class="post-metadata">

**Author:** ![Hugo\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@Hugo\_L](https://www.ruby-forum.com/u/Hugo_L)\
**Post date:** [February 24, 2007, 4:21am UTC](https://www.ruby-forum.com/t/initializer-method-override/86216/5 "2007-02-24T04:21:33Z")

</div>

Hey,

Maybe my question is not formulated right. Here’s a second try:

I’d like to use RCSS-stylesheets instead of regular CSS-stylesheets.  
What  
this implies:

1. Need to put a new ‘connect’ mapping above the default routes for  
entire  
app
2. Need to create a special controller to handle the RCSSs
3. Need to move the RCSSs to the view folder

The problem:  
The RCSS files don’t seem to appear to the application when the RCSSsed  
app  
is used as a plugin.

A thing I’m not sure about:  
In routing.rb there is a mention that on should add a  
‘map.from\_plugin:your\_plugin’ call in a  
‘ApplicationController::Routing::Routes.draw do |map|…’ block  
Where should this block go?

Thanks,

Hugo

---

<div class="post-metadata">

**Author:** ![Hugo\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@Hugo\_L](https://www.ruby-forum.com/u/Hugo_L)\
**Post date:** [February 22, 2007, 11:15am UTC](https://www.ruby-forum.com/t/initializer-method-override/86216/6 "2007-02-22T11:15:08Z")

</div>

Hi Hugo,

Are you using the engines 1.2 release? If so, check the UPGRADING  
file…

- James

---

<div class="post-metadata">

**Author:** ![Hugo\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@Hugo\_L](https://www.ruby-forum.com/u/Hugo_L)\
**Post date:** [February 27, 2007, 1:59pm UTC](https://www.ruby-forum.com/t/initializer-method-override/86216/7 "2007-02-27T13:59:46Z")

</div>

On 2/24/07, Hugo L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> A thing I’m not sure about:  
> In routing.rb there is a mention that on should add a ‘map.from\_plugin  
> :your\_plugin’ call in a  
> ‘ApplicationController::Routing::Routes.draw do |map|…’  
> block  
> Where should this block go?

This is the code which is in your main config/routes.rb file.  
Essentially it’s talking about including ruotes defined within plugins  
into your routing. However, it may not be necessary to include any  
special routes.

The problems seem clearer in your earlier mail:

> 1. route in app’s route.rb (complains that controller is not found)
> 2. route and controller in main app (complains view isn’t there)

It seems like the controller isn’t being loaded from the plugin, when  
clearly it should be. Check the log output from the engines plugin,  
and the load paths for the routing system to be sure that your plugin  
is loaded and the controller can be found.
