gpt4 book ai didi

ruby-on-rails - 如何在rails 4中组织 Controller 目录而不会弄乱路由

转载 作者:行者123 更新时间:2023-12-03 17:34:07 25 4
gpt4 key购买 nike

首先......我喜欢让事情井井有条。因此,我的应用程序中的 Controller 列表只是在一个大目录中不断增长,这开始困扰我。

理想情况下,我可以构建一个子目录列表并组织我的 Controller 。你可以用命名空间来做到这一点,但是子目录会出现在 url 中,我真的不希望这种情况发生。

有没有人有不同的策略来保持他们的 Controller 、助手、模型和 View 的组织?

最佳答案

Ideally, I could construct a list of subdirectories and organize my controllers. You can do this with namespaces, but then the subdirectory shows up within the url, and I really don't want this to happen.



您可以 scope针对特定命名空间的路由。阅读 Controller Namespaces and Routing
scope module: 'admin' do
resources :posts, :comments
end

将在 /posts 生成路由而 Controller 在 Admin::PostsControllerapp/controllers/admin/posts_controller.rb 中找到.

关于ruby-on-rails - 如何在rails 4中组织 Controller 目录而不会弄乱路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22049382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com