[英]Rails : Namespacing vs Engines?
I am just getting started in a Rails project after a long time in the PHP world. 在PHP世界中待了很长时间之后,我才刚刚开始一个Rails项目。
This project is in a very early stage, meaning that is a good time to do major changes, and currently comprises two different rails modules, one for administrators and one for users, both in separate rails instances. 该项目处于早期阶段,这意味着是进行重大更改的好时机,并且目前包含两个不同的Rails模块,一个用于管理员,一个用于用户,都在单独的Rails实例中。 What I would like to do is to merge both projects into a single rails instance, which I believe it will improve the manageability of the application in the long run.
我想做的是将两个项目合并到一个单一的Rails实例中,我相信从长远来看,它将提高应用程序的可管理性。
Both instances share the same database and each of them has a devise model for authentication. 两个实例共享同一个数据库,并且每个实例都有用于身份验证的设计模型。 I have been documenting myself about ways of merging both projects and I came up with two alternatives: the first would be to create two namespaces, one for users and another one for admins, and share the model and framework logic.
我一直在记录自己有关合并两个项目的方式,我想出了两种选择:第一种是创建两个名称空间,一个用于用户,另一个用于管理员,并共享模型和框架逻辑。 the second one would be to create engines for admins and users, which seems to be cleaner but much more complex.
第二个方法是为管理员和用户创建引擎,这看起来更干净,但更为复杂。
I have read a lot documentation and I am experimenting with rails, but at this point I am in need of a more experienced opinion. 我已经阅读了很多文档,并且正在尝试使用Rails,但是在这一点上,我需要一个更有经验的意见。
Thank you in advance, and I appreciate your thoughts on this. 预先谢谢您,我感谢您对此的想法。
Both namespaces and engines have pros and cons. 命名空间和引擎都各有利弊。 Which one to use will come down to your particular use case.
使用哪一个取决于您的特定用例。 For the most part, I recommend using namespaces as it tends to be easier and saves some headaches.
在大多数情况下,我建议使用名称空间,因为它更容易使用并且可以减轻一些麻烦。 Especially when sharing a data model.
尤其是在共享数据模型时。 However, engines are great when you want to share common isolated behavior in multiple applications.
但是,当您想在多个应用程序中共享常见的隔离行为时,引擎非常有用。
Pros 优点
Cons 缺点
Isolate related functionality
benefit. Isolate related functionality
优势的某些价值。 Pros 优点
Cons 缺点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.