Override a Rails Engine controller action

Marco Borromeo picture Marco Borromeo · May 21, 2010 · Viewed 9.1k times · Source

i'm using a Rails engine, but i need to customize some controllers actions.

I actually forked the engine, and implementing those customizations into my own fork, but i was wondering if there is an official way in Rails Engines to override and customize controllers.

Answer

nathanvda picture nathanvda · May 21, 2010

Just define a controller with the same name in your own app\controllers folder, and it will be found first. That way you can easily customize it.

Please note: because it is found first, you replace the entire controller from the engine. This could be exactly what you want. In some cases, you just want to adjust a little, then it is much better to reopen the class, and only redefine what is needed.

Examples to do is can be found here: http://edgeguides.rubyonrails.org/engines.html#overriding-models-and-controllers