1

我是 Rails 新手,我正在尝试路由 0.0.0.0:3000/ratings/list 到控制器ratings和方法list

但相反,我将index方法list作为参数

我的 routes.rb 就是这样

resources :ratings
  match 'ratings/:won/update/:lost' => 'ratings#update'
  match 'ratings/list' => 'ratings#list'

和耙路线是

ratings      GET    /ratings(.:format)                   ratings#index
             POST   /ratings(.:format)                   ratings#create
  new_rating GET    /ratings/new(.:format)               ratings#new
 edit_rating GET    /ratings/:id/edit(.:format)          ratings#edit
      rating GET    /ratings/:id(.:format)               ratings#show
             PUT    /ratings/:id(.:format)               ratings#update
             DELETE /ratings/:id(.:format)               ratings#destroy
                    /ratings/:won/update/:lost(.:format) ratings#update
ratings_list        /ratings/list(.:format)              ratings#list
4

2 回答 2

4

最好的方法是使用收集路线

resources :ratings do
  collection do
    get 'list'
  end
end
于 2012-11-22T20:38:24.310 回答
1

尝试

match 'ratings/list' => 'ratings#list'

resources :ratings

Rails 路线先到先得!

于 2012-11-22T20:29:41.130 回答