Duplicate routes?

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...

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.

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

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.