Reputation: 25652
I have an administration controller for my Rails application, but its getting large and unwieldly. Here is a sample:
get '/administration/events', :controller => :administration, :action => :event_index
get '/administration/events/new', :controller => :administration, :action => :event_new
post '/administration/events/create', :controller => :administration, :action => :event_create
get '/administration/events/:id/edit', :controller => :administration, :action => :event_edit
post '/administration/events/:id/update', :controller => :administration, :action => :event_update
delete '/administration/events/:id/delete', :controller => :administration, :action => :event_delete
It works, but is there a better way of doing it? (my actual routes for the controller are 3 or 4 times this number of entries.
Upvotes: 1
Views: 49
Reputation: 50057
You seem to have build one giant controller with a lot of actions handling a set of resources. The example you show: events
. This should be in a separate Administration::EventsController
.
Your url's seem REST-style, now you should match that to your app-structure.
Your directory structure should look like this
/app
/controllers
/administration
events_controller.rb
..
And then your routing will become
namespace :administration do
resources :events
# ... other resources ...
end
Upvotes: 2
Reputation: 4713
You should use namespacing instead:
namespace :administration do
resources :events
end
Upvotes: 4