gpt4 book ai didi

ruby-on-rails - 是否可以将 Rails Controller 文件放在 app/controllers 子目录中?

转载 作者:行者123 更新时间:2023-12-04 06:14:54 24 4
gpt4 key购买 nike

我正在使用 Rails 3,我想将一些 Controller 文件从 app/controllers 移动到 app/controllers/a-subdirectory。我不想为这些 Controller 命名空间,它们不对应于嵌套资源。只是为了有一个更有条理的文件结构。

当我尝试将 articles_controller 转到 app/controllers/a-subdirectory 并调用相关的路由路径助手时,我收到错误 ActionController::RoutingError: uninitialized常量 ArticlesController

有没有办法告诉 Rails 在 app/controllers 中递归查找 Controller 文件?

最佳答案

最后只需将 app/controllers/a-subdirectory 添加到 autoload_paths 即可:

config.autoload_paths += %W(
#{config.root}/app/controllers/a-subdirectory
)

关于ruby-on-rails - 是否可以将 Rails Controller 文件放在 app/controllers 子目录中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9435186/

24 4 0