ericalli
ericalli

Reputation: 1233

Rails App with Multiple Namespaces

I'm getting started on a large Rails project that will consist of several independent areas including and admin area, front-end website, user area, and api.

Would it be wise to create say, 3 namespaces for these sections (leaving the front-end website as the root)?

There doesn't seem to be a general rule regarding namespaces and it seems like the right choice for organizational purposes since each area would require several controllers.

In my past Rails projects I always namespace the admin, but in this case, are there any drawbacks to having multiple namespaces in the long run (in regards to routing / interacting with other namespaces)?

Any advice would be much appreciated!

Upvotes: 2

Views: 2654

Answers (3)

drhenner
drhenner

Reputation: 2230

checkout http://www.ror-e.com and the github app https://github.com/drhenner/ror_ecommerce It has several namespaces and most namespaces have their own base_controller.

Upvotes: 0

Kalendae
Kalendae

Reputation: 2244

no drawbacks only advantages if the namespaces make sense. Obviously having too many namespaces might be confusing and pointless but breaking up admin/client/public is a pretty common use case for using namespaces.

just make sure you give all your controllers unique names, so you don't run into the problem this guy ran into with namespaces: http://blog.philburrows.com/articles/2008/05/02/rails-namespaces-rock-rails-namespaces-suck-/

Upvotes: 5

Dan Fox
Dan Fox

Reputation: 729

If your project really does consist of logically independent areas then I don't see a downside. Any routing situation can be implemented with minimal effort, so that's not a dealbreaker.

One think you will have to keep in mind is that your project is going to have one extra level of directory nesting. For example, you can't just look in the views directory and get a good idea of all of your views, because they will all live in directories corresponding to their namespace (the same goes for tests). This is often desired, however, as it helps things stay a little more organized.

Upvotes: 3

Related Questions