Rails路由直接索引操作以显示操作

时间:2010-04-20 16:54:37

标签: ruby-on-rails routes

所以我为一个练习模型创建了一些rspec_scaffold,并将“map.resource:exercises”添加到我的路径文件中,当“/ exercise”url呈现show动作时,我感到很惊讶。有没有搞错?为什么不渲染索引操作?

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"}

1 个答案:

答案 0 :(得分:18)

使用单词resource时设置单一路线。请改用它。

map.resources :exercises