Forum: Ruby on Rails Routing with namespaces using edge rails

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7576c6f4d81186cd44e4006be6e7c53e?d=identicon&s=25 Peter (Guest)
on 2007-07-19 00:47
(Received via mailing list)

I was wondering if anyone came across a similar scenario when working
with namespaced routes with edge rails.

Consider an application with controllers customers and products that
also have other resources.

map.resources :customers do |customer|
  customer.resources :notes
  customer.resources :tags

map.resources :products do |product|
  customer.resources :notes
  customer.resources :tags

Now of course this poses a problem as it stands because the notes and
tags controllers will conflict.  I know there are polymorphic routes/
controllers (
polymorphic-controllers.html) however this doesnt make sense if the
controllers have little shared logic/behaviour; only a common name.  I
know I can just use a different name, but with the addition of
namespaces this should no longer be a concern with a proper design.

So.. I'm thinking something like:


with routes like:

map.namespace(:customers) do |customers|
  customers.resources :root, :has_many => [:tags, :notes]
map.namespace(:products) do |products|
  products.resources :root, :has_many => [:tags, :notes]

creating routes like:

This will work. But we have an unnecessary /root/ in the route.  I
suppose the solution would be adding a flag to the namespace function
to pass a root controller with a default name of "root_controller" so
the root of the namespace can itself be a resource.  Can this be done?
What do you guys think about it as an addition to rails?

This leads me to another scenario.  Namespaced models.... quite simply
as it stands you can in /app/models/ make a folder called /customer/
there add tag.rb and note.rb.  With models Customer::Tag and
Customer::Note.  One thing is the table_name will remain "tags" and
"notes", which in this case should be prefixed by the namespace name
like "customer_tags" and "customer_notes".  Also with the ability to
have a root model like Customer in /customer/root.rb.

I'd love to hear that this can already be done as rails stands.  I can
make the patches and submit them, however I don't want to divulge from
other design considerations.


This topic is locked and can not be replied to.