Admin Interface in Rails

I have an admin controller located in controllers/admin/admin_controller.rb I also have a page controller located in controllers/admin/pages_controller.rb pages_controller.rbinherits from admin_controller.rb in routes.rb, I have an admin namespace as such:

map.namespace :admin do |admin|
   admin.resources :pages
end
  • I want the admin to have basic CRUD functions in pages_controller.rb(I know how to do this)
  • I want methods indexand to showbe accessible to end users
  • I would like the show and index actions to use separate views, but the same code.

Questions:

  • Should I create a new one pages_controllerfor the front-end or share methods indexand show?
  • If a shared resource, how can I display individual views depending on whether the URL /admin/pagesor/pages
  • If share, should it be placed pages_controllerin /controllers/admin(where is it now) or just in /controllers?

Many thanks.

+5
source share
1 answer

I would keep them separate. Although the logic may be now, now they act in different ways. Keeping them separate will help you with security and allow you to make changes later, if necessary, for example, you can decide when loading a page that the administrator’s request should fulfill: enable something else, etc. On routes you can add:

map.resources :pages, :only => [:index, :show]

/, . /admin/pages /view/. , .

+3

All Articles