Hey,

so you're saying that you are using the same resource names (notes,  
tags) but you want those routes to go to different controllers?

map.resources :customers do |customer|
   customer.resources :notes, :controller => 'customer_notes'
   customer.resources :tags, :controller => 'customer_tags'
end

map.resources :products do |product|
   customer.resources :notes, :controller => 'product_notes'
   customer.resources :tags, :controller => 'product_tags'
end

In edge-rails your url helpers will automatically be name-prefixed so:

customer_notes_path #=> /customer/3/notes, controller ==  
CustomerNotesController

etc etc

HTH,
Trevor

On 18-Jul-07, at 12:01 PM, Peter wrote:

>
> Hi,
>
> 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
> end
>
> map.resources :products do |product|
>   customer.resources :notes
>   customer.resources :tags
> end
>
> 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 (http://revolutiononrails.blogspot.com/2007/05/drying-up-
> 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:
>
> /app/controllers/customers/root_controller.rb
> /app/controllers/customers/tags_controller.rb
> /app/controllers/customers/notes_controller.rb
> /app/controllers/products/root_controller.rb
> /app/controllers/products/tags_controller.rb
> /app/controllers/products/notes_controller.rb
>
> with routes like:
>
> map.namespace(:customers) do |customers|
>   customers.resources :root, :has_many => [:tags, :notes]
> end
> map.namespace(:products) do |products|
>   products.resources :root, :has_many => [:tags, :notes]
> end
>
> creating routes like:
> /customers/root/#{root_id}
> /customers/root/#{root_id}/tags/#{id}
> /customers/root/#{root_id}/notes/#{id
> /products/root/#{root_id}
> /products/root/#{root_id}/tags/#{id}
> /products/root/#{root_id}/notes/#{id
>
> 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.
>
> Regards,
>
> Peter
>
>
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to