rails 路由:具有不同命名空间的嵌套资源 [英] rails routing: nested resources with different namespace

查看:49
本文介绍了rails 路由:具有不同命名空间的嵌套资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 acts_as_commentable GEM 向我的帖子模型添加评论.我使用 ABC 作为命名空间,所以我所有的控制器和模型都命名为 ABC::Post、ABC::User 等.

I am trying to use the acts_as_commentable GEM to add comments to my Post Model. I am using ABC as namespace, so all my controller and models named as ABC::Post, ABC::User, etc.

目前我的路由设置如下.

Currently my routing setup is as following.

namespace :abc do
  resources :post do 
    resources :comments
  end
end

生成的路由URL为

POST   /abc/post/:id/comments(.:format)          abc/comments#create

我怎样才能做到

POST   /abc/post/:id/comments(.:format)         /comments#create

推荐答案

找到答案

namespace :abc do
    resources :post do 
        resources :comments, controller: '/comments'
  end
end

这篇关于rails 路由:具有不同命名空间的嵌套资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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