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:
match "/editor/usynkdataeditor/saveusynkeditor"
,
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:
class Editor::UsynkdataeditorController < ApplicationController
def saveusynkeditor
end
end
As far as routes are defined, you can do something like:
MyApplication::Application.routes.draw do
namespace :editor do
get "usynkdataeditor/saveusynkeditor"
end
end
Whish will give you route:
$ rake routes
editor_usynkdataeditor_saveusynkeditor GET /editor/usynkdataeditor/saveusynkeditor(.:format) editor/usynkdataeditor#saveusynkeditor
Or, preferably just use restful routes instead of saveusynkeditor like this:
MyApplication::Application.routes.draw do
namespace :editor do
resources :usynkdataeditor do
collection do
get :saveusynkeditor
end
end
end
end
when you will get:
$ 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
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With