Trouble understanding Routes

Hey Everyone, I'm new to Rails and working through the book Simply Rails 2. I've just hit one of my first large snags.

This *was* my routes file:

  map.resources :stories, :has_many => :votes, :collection => { :bin => :get }   map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format'   map.resource :session   map.root :controller => 'stories'   map.resources :users

my problem was anytime I traveled to the url /users/1-username/ i got an error saying the only action was 'show' Which did and did not make sense to me. It did make sense becuase the only action in my controller was show. and in both theory (and I tried it and it worked) the url should be /users/show/1-username. Which worked without a problem. But of course the book only user the /users/ 1-username/ url.

So after some time i changed my routes file to:

  map.resources :users   map.resources :stories, :has_many => :votes, :collection => { :bin => :get }   map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format'   map.resource :session   map.root :controller => 'stories'

Which fixed my problem. I can now access /users/1-username/ as expected (displays user information).

But I really don't understand why. Why is it now the controller is defaulting to it's only action but before it was not?

Thanks for the responses. I think I understand it now so I'll recap real quick

// Routes get written in a priority order. Specialized routes on the top (in this case assuming a RESTful manner from the controllers)   map.resources :users   map.resource :session   map.resources :stories, :has_many => :votes, :collection => { :bin => :get }

// And the default layout for all routes not specifically set above   map.root :controller => "stories"   map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format'

Thanks again, brianp

Sijo,

That is not necessarily good advice. You don't always need (or want) these default routes.

Even the comments produced automatically when creating a new Rails app tell you this:

# Install the default routes as the lowest priority. # ...You should consider removing them or commenting them out if you're using named routes and resources.