Rails 路由:向根添加(浅)关注 [英] Rails routing: add (shallow) concern to root

查看:44
本文介绍了Rails 路由:向根添加(浅)关注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 routes.rb 中,我定义了一个问题,如下所示:

In my routes.rb, I defined a concern like below:

concern :namespaceable do
  resources :comments do
    resources :replies
  ...

现在,我可以将这个问题添加到任何资源中:

Now, I can add this concern to any resources:

resources :groups, concerns: :namespaceable, shallow: true

但是如何将这个问题添加到根目录中,以便我可以有以下路线

But how can I add this concern shallowly to the root, so that I can have following routes

  • /评论
  • /comments/{comment_id}
  • /comments/{comment_id}/replys
  • /replys/{reply_id}

非常感谢!

推荐答案

只需要在主文件中写concerns: :namespaceable

Rails.application.routes.draw do

  concern :namespaceable do
    resources :comments do
    resources :replies
    ...
  end

  concerns: :namespaceable # Will add to root namespace

end

这篇关于Rails 路由:向根添加(浅)关注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆