我已经在routes.rb
上resources :questions, except: [:show] do
get '/resource/:subject/:id', to: 'resource#show', as: "resource", param: [:name, :id]
它说:
无效的路由名称,已经在使用中:"资源"您可能已经使用
:as
选项定义了具有相同名称的两个路由,或者您可能正在覆盖已由资源定义的路由,并具有相同的命名
我知道资源创建两个使用相同路径的路由show
和destroy
都使用resource_path
,如何在内部创建它?以及我如何生成我的路线以显示毁灭中的路线?
消除不需要路由的好方法是指定:唯一选项
resources :user, :only => [:edit]
而不是
resources :user, :except => [:new, :create, :edit, :update, :show, :destroy]
在我看来,您可以进行展示,然后定义您想要的路线。看看这是否有效:
resources :questions, except: :show
get '/resource/:subject/:id',
to: 'resource#show',
as: "resource", # This is where the error is.
param: [:name, :id]
编辑:啊,是的。:由于参数需要一个不同的名称。这将有效:
resources :questions, except: :show
get '/resource/:subject/:id',
to: 'resource#show',
as: "resource_show",
param: [:name, :id]