Hi, I have the following in routes.rb map.resources :districts do |district| district.resources :circuits, :name_prefix => ''district_'' end map.resources :circuits I want full CRUD for circuits at /circuits but only partial CRUD at /districts/?/circuits (index and new). This is to avoid too many levels of nesting (there are several more to come). I have got this fine for the UI (the links take you around exactly as I want). But the extra urls are still available. 1. How do I detect in the controller show if the url is /districts/1/circuits/1 which I want to redirect to the un-nested version at /circuits/1 ? 2. How do I know in index of controller whether I am /districts/1/circuits (limit to only district 1) or /circuits (list all)? I guess it will be fairly obvious that I am pretty much a rails newbie. But I have looked in the Agile bk 2nd ed and as many articles on nested resources as I can find. Thanks Dave --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
1. If the action was called through the nested route "/districts/1/ circuits/1", params[:district_id] would be set. Otherwise it wouldn''t. 2. same here. look for params[:district]. If params[:district]: @circuits = Districts.find_by_id(params[:district_id]).ciruits else @circuits = Circuit.find(:all) end On 30 Jun., 02:26, Dave Warnock <dwarn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have the following in routes.rb > > map.resources :districts do |district| > district.resources :circuits, :name_prefix => ''district_'' > end > > map.resources :circuits > > I want full CRUD for circuits at /circuits but only partial CRUD at > /districts/?/circuits (index and new). This is to avoid too many levels > of nesting (there are several more to come). > > I have got this fine for the UI (the links take you around exactly as I > want). But the extra urls are still available. > > 1. How do I detect in the controller show if the url is > /districts/1/circuits/1 which I want to redirect to the un-nested > version at /circuits/1 ? > > 2. How do I know in index of controller whether I am > /districts/1/circuits (limit to only district 1) or /circuits (list all)? > > I guess it will be fairly obvious that I am pretty much a rails newbie. > But I have looked in the Agile bk 2nd ed and as many articles on nested > resources as I can find. > > Thanks > > Dave--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The simplest thing you could do is check for the presence of params [:district_id] in the circuits controller. -- Benjamin Curtis http://www.bencurtis.com/ -- blog http://agilewebdevelopment.com/rails-ecommerce -- build e-commerce sites with Rails On Jun 29, 2007, at 5:26 PM, Dave Warnock wrote:> > Hi, > > I have the following in routes.rb > > map.resources :districts do |district| > district.resources :circuits, :name_prefix => ''district_'' > end > > map.resources :circuits > > I want full CRUD for circuits at /circuits but only partial CRUD at > /districts/?/circuits (index and new). This is to avoid too many > levels > of nesting (there are several more to come). > > I have got this fine for the UI (the links take you around exactly > as I > want). But the extra urls are still available. > > 1. How do I detect in the controller show if the url is > /districts/1/circuits/1 which I want to redirect to the un-nested > version at /circuits/1 ? > > 2. How do I know in index of controller whether I am > /districts/1/circuits (limit to only district 1) or /circuits (list > all)? > > I guess it will be fairly obvious that I am pretty much a rails > newbie. > But I have looked in the Agile bk 2nd ed and as many articles on > nested > resources as I can find. > > Thanks > > Dave > > >--~--~---------~--~----~------------~-------~--~----~ 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 Thorsten & Ben, Now working as I want. Dave --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---