Setting the right routes

I’m trying to create an admin section in my application which can be
accessed through www.myapp.com/admin. I’m going to need to administer
two models through the admin section. I have a generated the
controllers for Admin::Image and Admin::Project. That created a
subdirectory under the controllers directory called admin and I can
access each controller through www.myapp.com/admin/image or
应用宝官网-全网最新最热手机应用游戏下载.

Now what I want to do is make a root admin page from which
administrators will be able to select whether they want to go to the
image admin or the project admin. I tried creating an admin controller
in the top level directory but then when I go to
www.myapp.com/admin/image it says no action ‘image’ found in controller
‘admin’. So it’s assuming that i’m looking in the controller admin for
the action ‘image’ when really what i want is for it to go to the image
admin section.

what’s the best way to set this up?

You can’t have a controller with the same name as a module. (At least
when I tried that I ran into problems that I didn’t know how to work
around.)

Is there a big reason you split the image and project admin functions
into separate controllers? Perhaps you are being lazy and relying on
scaffolding? If so, it’s probably simplest to just have one admin
controller that can work on both images and projects. I recently did the
same thing myself and it works just fine. Also makes handling the
authentication for admin functions simple, as everything is in one
controller.

If you want to keep the controllers separate, try this. Create a third
controller, Admin::Root. Your routes would be something like:

map.connect ‘admin’ :controller => ‘admin/root’, :action => ‘index’
map.connect ‘:controller/:action/:id’

In the default route, :controller will map to the controller in the
module, either admin/root, admin/image or admin/project.

–josh

Saad Shakhshir wrote:

I’m trying to create an admin section in my application which can be
accessed through www.myapp.com/admin. I’m going to need to administer
two models through the admin section. I have a generated the
controllers for Admin::Image and Admin::Project. That created a
subdirectory under the controllers directory called admin and I can
access each controller through 应用宝官网-全网最新最热手机应用游戏下载 or
应用宝官网-全网最新最热手机应用游戏下载.

Now what I want to do is make a root admin page from which
administrators will be able to select whether they want to go to the
image admin or the project admin. I tried creating an admin controller
in the top level directory but then when I go to
应用宝官网-全网最新最热手机应用游戏下载 it says no action ‘image’ found in controller
‘admin’. So it’s assuming that i’m looking in the controller admin for
the action ‘image’ when really what i want is for it to go to the image
admin section.

what’s the best way to set this up?