2013-09-22 76 views
0

如何使第二條路線有效?覆蓋資源的「顯示」路線

resources :users, only: [:edit, :update] 
get ':id', :to => 'users#show', :as =>'user' 

的Rails給出錯誤,因爲第二行:(擴大我的意見,未來的觀衆參考)

Invalid route name, already in use: 'user' You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created 
+0

嘗試切換路線的順序,以改變他們的優先級。 – kwarrick

+0

謝謝!有用!你能把它作爲答案嗎? – Gediminas

回答

1

切換路線的順序將改變優先級,從而將get路由首選項設置爲RESTful路由。

從文檔中的一個新的config/routes.rb

# The priority is based upon order of creation: first created -> highest priority. 
    # See how all your routes lay out with "rake routes". 
+0

切換順序會導致資源的索引故障,因爲它與「get」行匹配空ID:。任何解決方案? –