Nested Rail Motors

Is it possible to embed (install) Rails engines inside other Rails engines?

I am working on a Rails 3.1 application that I want to split into several different sections and turn each section into Rails engines. However, I also want the whole application to turn into a Rails engine.

+4
source share
2 answers

Think about the benefits you get from nested engines. Nesting means connecting, and if you want to improve maintainability and testability, you must reduce this connection. I think that the ideal engine should work autonomously easily - that’s why you have a dummy application created in the test directory. Of course, you can keep nesting or maintain common material in the main application, but you will see that with a growing code base it is more difficult to maintain tests with tightly related dependencies.

As a solution, I would try composition. Place the engine catalogs next to each other, but use the nested modules:

 engines/foo_project - namespaced FooProject::* engines/foo_project_user - namespaced FooProjectUser::* or FooProject::User::* 

If there is something that FooProject::User is required of FooProject , then ideally it should be extracted to another engine, for example FooProject::Layout . In the other direction, the main application should pass the User material to FooProject . Add integration tests to the main tier of the application and you will get ordnung.

0
source

Source: https://habr.com/ru/post/1412876/


All Articles