开发者

Admin interface in Rails

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜