rails route设置了一条新路径

时间:2012-11-22 20:26:06

标签: ruby-on-rails routes

我是铁杆新手,我试图路线 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'

和rake路线是

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

2 个答案:

答案 0 :(得分:4)

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

resources :ratings do
  collection do
    get 'list'
  end
end

答案 1 :(得分:1)

尝试

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

resources :ratings

Rails路线先到先得!