hi, I am using: map.resources :users, has_many => ''events'' to route a new app I am working on. Problem is that now, i can view the index action for my events controller at both: localhost:3000/events and localhost:3000/users/1/events I of course prefer the second of the two but am a bit worried about where i might have went wrong to end up with the duplicates... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
nospacesalloneword wrote:> hi, I am using: map.resources > > :users, has_many => ''events'' > > to route a new app I am working on. Problem is that now, i can view > the index action for my events controller at both: > > localhost:3000/events > > and > > localhost:3000/users/1/events > > I of course prefer the second of the two but am a bit worried about > where i might have went wrong to end up with the duplicates... >The ''localhost:3000/events'' is being provided by ''map.resources :events''. If you delete that one line then that will won''t work anymore but you''ll still have the other. However, that means that you also won''t be able to go to ''localhost:3000/events/42'', but would instead need to go to ''localhost:3000:/users/6/events/42''. My recommendation would be to not worry about the duplicates. If you don''t ever link to ''localhost:3000/events'' then it won''t get hit much, and it wouldn''t be hard to write a little code to redirect to someplace appropriate if a params[:user_id] isn''t set in the index action. -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
nospacesalloneword wrote:> hi, I am using: map.resources > > :users, has_many => ''events'' > > to route a new app I am working on. Problem is that now, i can view > the index action for my events controller at both: > > localhost:3000/events > > and > > localhost:3000/users/1/events > > I of course prefer the second of the two but am a bit worried about > where i might have went wrong to end up with the duplicates...That is not a bug, you can ultimately have many routes map to the same controller and action. In this way, it can be made to very intuitive for the user where they can guess at the url and it just works.. hth ilan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 3/4/08, Ilan Berci <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > nospacesalloneword wrote: > > hi, I am using: map.resources > > > > :users, has_many => ''events'' > > > > to route a new app I am working on. Problem is that now, i can view > > the index action for my events controller at both: > > > > localhost:3000/events > > > > and > > > > localhost:3000/users/1/events > > > > I of course prefer the second of the two but am a bit worried about > > where i might have went wrong to end up with the duplicates... > > > That is not a bug, you can ultimately have many routes map to the same > controller and action. In this way, it can be made to very intuitive > for the user where they can guess at the url and it just works..While this is all true. Ultimately it''s under your control. No one has addressed why localhost:3000 is being recognized: Assuming that the OP meant that he had a config/routes.rb something like this: ActionController::Routing::Routes.draw do |map| map.resources :users, :has_many => ''events'' # Install the default routes as the lowest priority. map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' end It''s those last two lines which are providing the ''extra'' routes in question. There''s nothing stopping you from deleting those lines if you don''t want/need the default routes. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---