# Default route within a namespace

**URL:** <https://www.ruby-forum.com/t/default-route-within-a-namespace/147021>\
**Category:** Rails\
**Created:** [August 27, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/default-route-within-a-namespace/147021 "2008-08-27T17:31:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fishwebby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b77776/32.png) [@fishwebby](https://www.ruby-forum.com/u/fishwebby)\
**Post date:** [August 27, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/default-route-within-a-namespace/147021/1 "2008-08-27T17:31:48Z")

</div>

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](http://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](http://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

---

<div class="post-metadata">

**Author:** ![fishwebby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b77776/32.png) [@fishwebby](https://www.ruby-forum.com/u/fishwebby)\
**Post date:** [August 28, 2008, 9:07am UTC](https://www.ruby-forum.com/t/default-route-within-a-namespace/147021/2 "2008-08-28T09:07:22Z")

</div>

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](http://example.com/admin) and [example.com/admin/users](http://example.com/admin/users) both work.

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

Cheers  
Dave
