是否可以将Rails控制器文件放置在app/controllers子目录中?
问题描述:
我用Rails 3,我想一些控制文件移动从app/controllers
到app/controllers/a-subdirectory
。我不想命名空间这些控制器,他们不对应嵌套的资源。它只是有一个更有组织的文件结构。是否可以将Rails控制器文件放置在app/controllers子目录中?
当我尝试到articles_controller
到app/controllers/a-subdirectory
并调用相关的路由路径助手时,我得到错误ActionController::RoutingError: uninitialized constant ArticlesController
。
它有没有办法告诉Rails递归查询控制器文件app/controllers
?
答
最后可以通过简单地增加app/controllers/a-subdirectory
到autoload_paths
做:
config.autoload_paths += %W(
#{config.root}/app/controllers/a-subdirectory
)
我不工作,这同时我想继续像'/ posts'路径创建像'/我-DIR/posts'路径。 – Florent2 2012-02-26 16:22:36