Is this possible? domain.com/users domain.com/users/1/products domain.com/products I''d like to view all the products for a User and also all of the entire products. From what I''ve tried, this does not work: map.resources :users do |users| users.resources :products end map.resources :products --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You have to use a name_prefix for the nested resources. Jamis Buck wrote about it two months ago: http://weblog.jamisbuck.org/2007/2/5/nesting-resources cheers :) -- bobes On Apr 25, 11:10 am, jko170 <jko...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is this possible? > > domain.com/users > > domain.com/users/1/products > > domain.com/products > > I''d like to view all the products for a User and also all of the > entire products. From what I''ve tried, this does not work: > > map.resources :users do |users| > users.resources :products > end > > map.resources :products--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot bobes! Specifically comment number 15 was exactly what I was looking for. My routes now look like this: map.resources :users do |users| users.resources :products, :controller => "user_products" end map.resources :products Now I obviously had to create an extra controller: UserProducts < ApplicationController --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Actually my last post didn''t work. It would read the User id as the action and the user_products as the id. I changed my routes to this with success: map.resources :user_products, :path_prefix => "users/:user_id" Is this the best way to do this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Looks like my second post didn''t go through. Here is what I had map.resources :users do |users| users.resources :products, :controller => "user_products" end map.resources :products --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So you''ve got a ProductsController and UserProductsController? If so, then this could be a good way to go. If the views are the same for user products and all products than having one controller and one set of views is a better solution. The routes would be: map.resources :users do |users| users.resources :products, :name_prefix => "user_" end map.resources :products And in actions you would have something like: def index params[:user_id].nil? ? Products.find(:all) : User.find (params[:user_id]).products end You could also extract the condition to a before_filter, let me know if you have any problems with this... -- bobes On 25/04/07, jko170 <jko170-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Actually my last post didn''t work. It would read the User id as the > action and the user_products as the id. I changed my routes to this > with success: > > map.resources :user_products, :path_prefix => "users/:user_id" > > Is this the best way to do this? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I actually needed to use the same views so this works perfectly. I ended up using an if/else loop because I needed to render one different view. Thanks! (now I have to go back and delete all the user_products files .....) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I actually needed to use the same views so this works perfectly. I ended up using an if/else loop because I needed to render one different view. Thanks! (now I have to go back and delete all the user_products files .....) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---