Rails应用程序文件夹目录结构 [英] rails app folder directory structure
问题描述
这是Rails项目中的应用程序控制目录
对Rails进行自学,但据我了解,如果我在app文件夹中创建目录,则必须用匹配的路由完成路由文件,例如:
match / editor / usynkdataeditor / saveusynkeditor
向社区提出的问题是,有一种更好的方法可以为特定的工作流程定义不同的目录结构,还是可以安全地在父控制器目录中定义所有控制器。
如果在controllers目录中创建其他目录,则实际上是在命名控制器的空间。
因此该控制器将是:
class Editor :: UsynkdataeditorController< ApplicationController
def saveusynkeditor
结束
结束
定义后,您可以执行以下操作:
MyApplication :: Application.routes.draw do
名称空间:editor do
获得 usynkdataeditor / saveusynkeditor
结束
结束
这将为您提供路线:
$耙路
editor_usynkdataeditor_saveusynkeditor GET / editor / usynkdataeditor /saveusynkeditor(.:format)编辑器/ usynkdataeditor#saveusynkeditor
或者,最好只使用静态路由而不是saveusynkeditor是这样的:
MyApplication :: Application.routes.draw do
namespace:editor do
资源:usynkdataeditor做
收集做
得到:saveusynkeditor
结束
结束
结束
结束
何时您将获得:
$耙线
saveusynkeditor_editor_usynkdataeditor_index GET /editor/usynkdataeditor/saveusynkeditor(.:format)编辑器/ usynkdataeditor#saveusynkeditor
editor_usynkdataeditor_index编辑器/usynkdataeditor(.:format)编辑器/ usynkdataeditor#index
POST /editor/usynkdataeditor(.:format)编辑器/ usynkdataeditor#create
new_editor_usynkdataeditor GET /editor/usynkdataeditor/new(.:format)编辑器/ usynkdataeditor#new
edit_editor_usynkdataeditor GET /editor/usynkdataeditor/:id/edit(.:format)编辑器/ usynkdataeditor#edit
editor_usynkdataeditor GET /editor/usynkdataeditor/:id(.:format)编辑器/ usynkdataeditor #显示
PUT /编辑器/usynkdataeditor/:id(.:format)编辑器/ usynkdataeditor#update
删除/editor/usynkdataeditor/:id(.:format)编辑器/ usynkdataeditor#destroy
很好的解释 http://guides.rubyonrails.org/routing.html#controller-namespaces-and 最后,回答您的问题: Here is a app contorller directory from Rails project doing a self study for rails, but from what I understand if I create a directory in the app folder then I have to do the complete the routes files with a match that route like: Question to the community is there a better way that I can define different directory structure for a specific workflow or is it safe to define all the controllers in parent controllers directory. If you create additional directory in controllers directory, you are effectively namespacing your controllers. So this controller would be: As far as routes are defined, you can do something like: Whish will give you route: Or, preferably just use restful routes instead of saveusynkeditor like this: when you will get: There is a really good explanation http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing of what you are trying to achieve in rails guides. Finally, to answer your question:
这篇关于Rails应用程序文件夹目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
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
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