如何使第二条路线发挥作用?
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 :(得分: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".