The correct way to do this is with engines. Each engine is like a standalone app, with it's own routes, test suite, etc, but you can have some common infrastructure like rake tasks, etc.
Can I have common namespaces in new rails applications?
-
26-06-2023 - |
Question
Is it possible to create whole rails applications under a common namespace?
Lets assume that my company name is Acme, Inc. and I have the following rails projects: Blog, Store, WebService.
By default, if I do something like rails new blog
the generated applications will be like:
module Blog
class Application < Rails::Application
module Store
class Application < Rails::Application
module WebService
class Application < Rails::Application
where every project/application is self contained and there is no implicit reference to the company. Ideally I would like to have all this applications under the company namespace, so we can refer to them as:
AcmeInc::Blog::Application
AcmeInc::Blog::Entities::Article
AcmeInc::Store::Application
AcmeInc::Store::Entities::Product
AcmeInc::Store::Entities::Order
AcmeInc::Store::Entities::Customer
etc...
Is this possible? Recommended?
Using: ruby-2.0.0-p451, rails 3.2.17
Update
Snapshot of generated files and project structure after doing rails new acme/blog as suggested:
Solution
OTHER TIPS
I think I am probably late here to answer this, as others have already suggested nice approaches. Like, maintaining code within one common repository and creating rails engine.
I would like to share this famous project called spree, which follows the architecture you're looking for. You can visit spree's code on github here.
For example:
Spree::Core
- spree_core engine as a gem to maintain all models and base modules etc.Spree::Backend
- spree_backend engine as a gem to maintain all admin related controllers, views, assets etc.Spree::Frontend
- spree_frontend engine as a gem to maintain user facing code i.e. controllers, views, assets related to it.
I guess you can use it as a reference for your application development.
If your trying to manage your code, why don't you just make a Blog Gem that you can include in each application. Then you would manage the code under one common repository for the Gem. Sees to me that's the Rails/Ruby way to do this