Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails engines extending functionality

I have an engine which defines some models and controllers. I want to be able to extend functionality of some models/controllers in my application (eg. adding methods) without loosing the original model/controller functionality from engine. Everywhere I read that you simply need to define controller with the same name in your application and Rails will automatically merge them, however it doesn't work for me and controller in engine is simply ignored (I don't think it's even loaded).

like image 441
Andrius Avatar asked Jun 03 '10 07:06

Andrius


People also ask

What is an engine in Rails?

1 What are Engines? Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the Rails::Application class inheriting a lot of its behavior from Rails::Engine .

What is Mount in Rails routes?

Mount within the Rails routes does the equivalent of a Unix mount . It actually tells the app that another application (usually a Rack application) exists on that location. It is used mostly for Rails Engines.


1 Answers

require MyEngine::Engine.root.join('app', 'models', 'my_engine', 'my_model')

before the model class definition in your application.

like image 69
Peder Avatar answered Oct 05 '22 22:10

Peder