How to a create a main admin page

You could set up an admin/welcome or admin/dashboard controller and then map to that with a custom route such as:

map.dashboard 'admin', :controller => 'admin/dashboard'


James Stewart wrote:


I have multiple sections of my site that need to be accessed
through an admin section. I was able to get them to work by using admin/ subfolder, but I would like to make a "dashboard" sort of page when going to just I'd like it to include a login form and once
logged in show a list of all the controllers in the admin/ directory.

I've searched through many different SVNs from RailsDay and have seen many sites that have their admin controllers in an admin/ folder, but none seem to have a default admin page that has links to each one.

Can someone please give me some help or point me in the right
direction?      You could set up an admin/welcome or admin/dashboard controller and
then map to that with a custom route such as:

map.dashboard 'admin', :controller => 'admin/dashboard'



I've done done my controllers in a RESTful way (with admin only access to the new/edit/create/update/destroy actions) and then had an admin controller whose index action is just what you're describing -- a dashboard type thing showing latest activity and giving various admin options (which link to the RESTful controllers). HTH CT

You'll want to make use of a before_filter in your controllers (or in a class that your controllers all inherit from):

You might also want to look into one of the authentication plugins, such as acts_as_authenticated and see how that is used:


John Saunders wrote:

Thanks, I ran the three commands for Acts as Authenticated then put before_filter :login_required at the top of my controllers in the admin/ folder but I'm getting "undefined method `login_required' for #<Admin::ScheduleController:0x282a5d0>". I read through the site you linked me to but I don't see anything that I missed. What do I need to do to define login_required?

-- Posted via

Hi John,

in your new account controller you should see this at the top:

# Be sure to include AuthenticationSystem in Application Controller instead   include AuthenticatedSystem

If you haven't done this already then just comment out "include AuthenticatedSystem" in your account controller and add it to your application controller.

rake db:migrate

"The way the plugin works is simple. The first thing you do is create the models and migration:

script/generate authenticated user account

(In older versions of the plugin, you needed to create the migration separately:

script/generate authenticated_migration

This should no longer be necessary.)

This will not only create your User model, but an Account controller, some unit and functional1 tests, and some libraries in lib/. Once that’s done, you can move the include AuthenticatedSystem from app/controllers/account_controller.rb to app/controllers/application.rb. This makes all the authentication methods available to all controllers."

so if you’ve run the generator to create your models, there should also now be migrations in db/migrate to create the required tables.