Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails routes direct index action to show action

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"}
like image 886
jspooner Avatar asked Apr 20 '10 16:04

jspooner


1 Answers

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

map.resources :exercises
like image 54
jdl Avatar answered Nov 12 '22 05:11

jdl