是否可以将Rails控制器文件放置在app/controllers子目录中?

问题描述:

我用Rails 3,我想一些控制文件移动从app/controllersapp/controllers/a-subdirectory。我不想命名空间这些控制器,他们不对应嵌套的资源。它只是有一个更有组织的文件结构。是否可以将Rails控制器文件放置在app/controllers子目录中?

当我尝试到articles_controllerapp/controllers/a-subdirectory并调用相关的路由路径助手时,我得到错误ActionController::RoutingError: uninitialized constant ArticlesController

它有没有办法告诉Rails递归查询控制器文件app/controllers

最后可以通过简单地增加app/controllers/a-subdirectoryautoload_paths做:

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

可以使用:path选项是,

resources :posts, :path => "/my-dir/posts" 

退房this guide以获取更多信息。

+0

我不工作,这同时我想继续像'/ posts'路径创建像'/我-DIR/posts'路径。 – Florent2 2012-02-26 16:22:36