在Rails 6中的名称空间之外指定控制器

米海特

我有这个当前的设置工作:

concern :commentable do
  resources :comments, only: %i[create destroy], controller: '/comments'
end

它在路线下用作

namespace :admin do
  resources :discussions, concerns: %i[commentable]
end

在rails 6中,当我这样做时,我得到:

ArgumentError('/ comments'不是受支持的控制器名称。这可能导致潜在的路由问题。请参阅https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use):

如何指定位于路由当前模块之外的控制器?

米海特

好吧,我没有找到解决办法,但找到了解决方法。

如果替换为namespace :adminscope '/admin/', module: :admin, as: :admin则可以controller: '/comments'用来引用当前名称空间之外的控制器。

concern :commentable do
  resources :comments, only: %i[create destroy], controller: '/comments'
end

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章