我的routes.rb中有一个条目,看起来像这样:
resources :baskets, :shallow => true, :only => :show
resource :owned, :only => [:create, :destroy]
end
get '/baskets/owned', :to => 'owners#index'
这创建的路线看起来像:
basket GET /baskets/:id(.:format)
baskets_owned GET /baskets/owned(.:format)
# ...
但现在,当我呼叫/篮下/拥有时,我得到的是:
Started GET "/baskets/owned" for 10.0.1.2 at 2011-06-09 10:31:33 -0400
Processing by BasketsController#show as JSON
Parameters: {"id"=>"owned"}
解决路由冲突最常用的方法是什么?
Rails从第一个定义的路由开始匹配路由,一直到找到匹配;使用第一个匹配的路由,而忽略所有其他路由。
解决问题的方法是将get '/baskets/owned'
路由置于resources
路由之前。