Default route within a namespace

Hello,

I have a question about a default route within a namespace.

I use the line

map.root :controller => ‘home’

to redirect requests to the root of my website to the ‘home’
controller, which works fine.

I also have a controller within the ‘admin’ namespace, defined like
this:

class Admin::UsersController < ApplicationController

So I can access this controller like this: example.com/admin/users
which also works fine.

However, I’m thinking that I’m going to have several controllers
within the admin namespace, so what I would like to do is be able to
go to example.com/admin and have a default controller within the admin
namespace (even if it just presents a page of links to each of the
controllers within that namespace). When I try to access /admin I get
a routing error (“No route matches ‘/admin’”). I thought perhaps I
could create an admin controller in the root but then I don’t see how
that wouldn’t get confused with the namespace.

The only other two lines in my routes.rb file are the default ones:

map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’

How can I create a default within the admin namespace? I’m new to
routes but from what I’ve read I’m slightly confused as to how to do
this.

Any help is greatly appreciated.

Many thanks
Dave

Whilist playing with routes I seem to have come across a solution that
works:

In my ‘home’ controller, I added an ‘admin’ method (that will just be
a list of links to the various controllers in the admin namespace),
and in routes.rb, after the ‘map.root’ line, I added this:

map.admin ‘admin’, :controller => ‘home’, :action => ‘admin’

Now example.com/admin and example.com/admin/users both work.

If there is a more idiomatic Rails way of doing it please let me
know! :slight_smile:

Cheers
Dave