views:

61

answers:

1

So I created some rspec_scaffold for an Exercise model and added "map.resource :exercises" to my routes file and I was surprised when the "/exercises" url rendered the show action. What the heck? Why doesn't that render the index action?

rake routes

new_exercises GET    /exercises/new(.:format)                           {:controller=>"exercises", :action=>"new"}
                edit_exercises GET    /exercises/edit(.:format)                          {:controller=>"exercises", :action=>"edit"}
                     exercises GET    /exercises(.:format)                               {:controller=>"exercises", :action=>"show"}
                               PUT    /exercises(.:format)                               {:controller=>"exercises", :action=>"update"}
                               DELETE /exercises(.:format)                               {:controller=>"exercises", :action=>"destroy"}
                               POST   /exercises(.:format)                               {:controller=>"exercises", :action=>"create"}
+4  A: 

You set up a singular route when you used the word resource. Use this instead.

map.resources :exercises
jdl
Ah thanks! I didn't even know there was a singular route.
jspooner
Solved my problem too +1
Charlie