Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have common namespaces in new rails applications?

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:

snapshot

like image 703
qbantek Avatar asked Nov 02 '22 02:11

qbantek


1 Answers

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.

http://guides.rubyonrails.org/engines.html

like image 120
Nader Avatar answered Nov 12 '22 22:11

Nader