覆盖资源的“show”路由

时间:2013-09-22 18:47:15

标签: ruby-on-rails-4

如何使第二条路线发挥作用?

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

1 个答案:

答案 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".