I''ve been looking around, and I can''t seem to find anything definitive on whether or not you can coax Routes into omitting the collection name when doing a nested resource; i.e. map.resource :users do |users| users.resources :pages # some other option here end to get: /users/:user_id/:id instead of /users/:user_id/pages/:id Is this functionality actually there? If not, *should* it be? The use-case scenario I''m thinking of is having users add pages to their site, so: /users/1 # user 1 view, which presumably lists the pages the user has /users/1/research # user 1''s research page /users/1/fun # user 1''s fun page I''m not really sure how this conform with the Rails philosophy... Nick --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Nick, On 6.12.2006, at 18.13, Nick Howell wrote:> to get: > /users/:user_id/:id > instead of > /users/:user_id/pages/:id > > > Is this functionality actually there? If not, *should* it be? The > use-case scenario I''m thinking of is having users add pages to their > site, so: > > /users/1 # user 1 view, which presumably lists the pages the user has > /users/1/research # user 1''s research page > /users/1/fun # user 1''s fun pageThis question belongs to the general Rails mailing list (cross- posted, please remove the core list from the recipients if you reply to this message), but here goes. AFAIK you cannot do that with restful routes. However, you only need a single named route before the restful route declarations to get what you want: map.user_page ''users/:user_id/:id'', :controller => "pages", :action => "show" map.resources :users do |users| users.resources :pages end That way you can use user_page_path(:user_id => @user, :id => @page) to get to that shorter url. For all other actions, the restful routes are used. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
Nick, In the example you give it''s really more of an issue of building a route that works for what you''re doing. What you''re trying to accomplish isn''t a resource. A resource would be one controller that taxes the standard HTTP verbs and maps them to actions. You''re just looking for a custom route like: map.connect ''/users/:user_id/:page_name'', :controller => ''pages'', :action => ''show'', :requirements => { :user_id => /\d+/ } You''ll need to make sure that doesn''t conflict with any other routes you already have. If you have any further questions it would be more appropriate to continue in the Rails mailing list. -Martin On 12/6/06, Nick Howell <nlhowell@gmail.com> wrote:> > > I''ve been looking around, and I can''t seem to find anything definitive > on whether or not you can coax Routes into omitting the collection name > when doing a nested resource; i.e. > > map.resource :users do |users| > users.resources :pages # some other option here > end > > to get: > /users/:user_id/:id > instead of > /users/:user_id/pages/:id > > > Is this functionality actually there? If not, *should* it be? The > use-case scenario I''m thinking of is having users add pages to their > site, so: > > /users/1 # user 1 view, which presumably lists the pages the user has > /users/1/research # user 1''s research page > /users/1/fun # user 1''s fun page > > I''m not really sure how this conform with the Rails philosophy... > > Nick > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---