1

I'm wondering what's Rails approach when it comes to creating a full-fledged admin control panel. And by full-fledged I mean a real control panel that could be used on a professional level, not personal/internal scaffolding.

I don't believe its stored in the same folder as the user interface as it's shown in the blog screencast or in Getting Started with Rails tutorial!

I'm certain the same model will be used everywhere but what about the views?

Please explain in details. I don't want to use my PHP mentality when starting my first real project in Rails.

Thanks.

emurad
  • 3,448
  • 10
  • 40
  • 47
  • What do you want your admin control panel to do? – Ant Jun 06 '11 at 08:57
  • Everything. Let's assume it's a news site with editors who can login to manage the stories, create categories, add new editors, etc etc. – emurad Jun 06 '11 at 12:25

3 Answers3

4

here you can find a list of rails plugins/engines to manage admin interfaces:

http://ruby-toolbox.com/categories/rails_admin_interfaces.html

I've used a bunch of them (typus and rails_admin), not bad at all.

also check the recent released ActiveAdmin

http://activeadmin.info/

Andrea Pavoni
  • 5,311
  • 2
  • 29
  • 44
2

It depends on the nature of your application, but there's nothing wrong with having the admin functions in the same view as the user; Just test your permission role before showing certain part of the display.

If you really need an admin only interface, you could namespace some controllers and views. There are other posts that deal with how to do this, such as The Rails Way - Namespaces

Community
  • 1
  • 1
DGM
  • 26,629
  • 7
  • 58
  • 79
  • 1
    Let's take a REAL application like 37signals Basecamp. Do you think their admin control panel (where they manage users, do the billing, etc) lives beside the user interface in term of controllers and views? – emurad Jun 06 '11 at 12:28
2

As hinted at by the previous answers namespacing is useful to keep admin functionality neatly separated from other user functionality, for example:

# In your routes

namespace :admin do
  resources :stories
  resources :editors
   #etc.
end

Then you'd put all your admin controllers in an 'admin' subfolder and always require an admin to access them:

# app > controllers > admin > stories_controller.rb

class Admin::StoriesController < ApplicationController

  before_filter :authenticate_admin!   # assuming you're using devise

  def index
    #etc.
  end

end

The advantage of this is you only have to check for admin in one place (the before_filter of an admin controller) rather than having to put conditionals everywhere in your normal controllers / views.

Ant
  • 3,877
  • 1
  • 15
  • 14
  • That sounds great. Is this doable in Rails out of the box or additional gems are needed? – emurad Jun 06 '11 at 12:40
  • @emurad It's out of the box functionality, apart from Devise for authentication, that's a gem. – Ant Jun 06 '11 at 13:05
  • 3
    Just as an addition to this, what i normally do is have `class AdminController` in my regular controllers folder, which has a before_filter method "require_admin" or similar, and have a subfolder in controllers called `admin`, which contains the controllers like `class Admin::StoriesController << AdminController`. That way all of your admin controllers are admin-only, and you can add any other shared functionality into AdminController. – Max Williams Jun 06 '11 at 13:11