views:

93

answers:

1

I have an admin controller located in controllers/admin/admin_controller.rb I also have a pages controller located in controllers/admin/pages_controller.rb pages_controller.rb inherits 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 have basic CRUD functionality in pages_controller.rb (I know how to do that)
  • I want the index and show methods to be available to front-end users
  • I would like the show and index actions to use separate views, but the same code.

Questions:

  • Should I create a new pages_controller for the front-end, or share the methods index and show?
  • If share, how would I display separate views depending on whether the url is /admin/pages or /pages
  • If share, should I place pages_controller in /controllers/admin (where it is now) or just in /controllers?

Thank you very much.

+2  A: 

I would keep them separate. Although the logic maybe the same now they are in effect two different things. Keeping them separate will help you with security and allow you to make changes later on if necessary, for example you may decide when loading a page the admin query should also :include something else etc. In the routes you can add:

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

Your will a views for each action/controller pair, e.g. one in view/admin/pages and one in the /view/pages. If these two are duplicating code, extract it into partials and render them from both.

tsdbrown
thank you very much!
yuval