这里是Rails项目Rails应用程序文件夹的目录结构
一个应用contorller目录做了Rails中自学,但是从我的理解,如果我在应用中创建文件夹目录,然后我有
match "/editor/usynkdataeditor/saveusynkeditor"
,
问题向社会是没有办法,我可以定义不同的目录结构,更好的办法:做完整的路线用火柴这条路线如文件对于特定的工作流程还是安全的定义父控制器目录中的所有控制器。
这里是Rails项目Rails应用程序文件夹的目录结构
一个应用contorller目录做了Rails中自学,但是从我的理解,如果我在应用中创建文件夹目录,然后我有
match "/editor/usynkdataeditor/saveusynkeditor"
,
问题向社会是没有办法,我可以定义不同的目录结构,更好的办法:做完整的路线用火柴这条路线如文件对于特定的工作流程还是安全的定义父控制器目录中的所有控制器。
如果您在控制器目录中创建其他目录,则可以有效地命名您的控制器。
所以该控制器将是:
class Editor::UsynkdataeditorController < ApplicationController
def saveusynkeditor
end
end
至于路由被定义,你可以这样做:
MyApplication::Application.routes.draw do
namespace :editor do
get "usynkdataeditor/saveusynkeditor"
end
end
韦思会给你的路线:
$ rake routes
editor_usynkdataeditor_saveusynkeditor GET /editor/usynkdataeditor/saveusynkeditor(.:format) editor/usynkdataeditor#saveusynkeditor
或者,最好只是使用宁静的路线,而不是像这样的saveusynkeditor:
MyApplication::Application.routes.draw do
namespace :editor do
resources :usynkdataeditor do
collection do
get :saveusynkeditor
end
end
end
end
时,您将获得:
$ rake routes
saveusynkeditor_editor_usynkdataeditor_index GET /editor/usynkdataeditor/saveusynkeditor(.:format) editor/usynkdataeditor#saveusynkeditor
editor_usynkdataeditor_index GET /editor/usynkdataeditor(.:format) editor/usynkdataeditor#index
POST /editor/usynkdataeditor(.:format) editor/usynkdataeditor#create
new_editor_usynkdataeditor GET /editor/usynkdataeditor/new(.:format) editor/usynkdataeditor#new
edit_editor_usynkdataeditor GET /editor/usynkdataeditor/:id/edit(.:format) editor/usynkdataeditor#edit
editor_usynkdataeditor GET /editor/usynkdataeditor/:id(.:format) editor/usynkdataeditor#show
PUT /editor/usynkdataeditor/:id(.:format) editor/usynkdataeditor#update
DELETE /editor/usynkdataeditor/:id(.:format) editor/usynkdataeditor#destroy
还有就是你正在努力实现在轨导什么一个很好的解释http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing。
最后,要回答你的问题:
这属于Namespacing,它通常被认为是做你想做的最好的方法。一探究竟。
这是不常见的,为什么你要移动子目录中的一些控制器?无论如何,这应该有所帮助:http://stackoverflow.com/questions/7583898/grouping-controller-in-subdirectories-for-nested-resources – 2012-03-30 15:50:10