# Routing and namespace

**URL:** <https://www.ruby-forum.com/t/routing-and-namespace/86065>\
**Category:** Rails\
**Created:** [February 19, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/routing-and-namespace/86065 "2007-02-19T17:03:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![antonaylward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@antonaylward](https://www.ruby-forum.com/u/antonaylward)\
**Post date:** [February 19, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/routing-and-namespace/86065/1 "2007-02-19T17:03:07Z")

</div>

I’m trying to set up and ‘admin’ interface for each of my models.

I have a controller for each of them under ‘app/controllers/admin/’  
book\_controller.rb  
page\_controller.rb  
and so on.

So as not to get in the way of normal use I’m ‘forcing’ a prefix in the  
routing/url with lines in routes.rb like

map.connect ‘/admin/page/:page/:action’,  
:controller =\> ‘admin/page\_controller’,  
:action =\> ‘show’,  
:requirements =\> { :page =\> page\_name\_requirement }

when I experiment with app.url\_for() in the console I get the results I  
expect.

But when I fire up the server and try to go to

[http://localhost](http://localhost).:3000/admin/page/ChapterOne

I get

NameError in Admin/web controllerController#list

uninitialized constant Admin::WebControllerController

Two questions:

Should my controller read:

```
class Admin::WebController < ApplicationController

```

which was how it was generated

and/or should the routing be fudged in some way.

Remember, this is not the ‘real’ application.  
The real application comes out at

```
   http://localhost.:3000/TheStoryofLitchfileld/ChapterOne

```

## and the routing for that is lower down in the routes.rb

“Quality refers to the extent to which processes, products, services,  
and  
relationships are free from defects, constraints and items which do not  
add  
value.”

- Dr. Mildred G Pryor, 1995

---

<div class="post-metadata">

**Author:** ![antonaylward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@antonaylward](https://www.ruby-forum.com/u/antonaylward)\
**Post date:** [February 19, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/routing-and-namespace/86065/2 "2007-02-19T18:17:20Z")

</div>

If you have a controller in app/controllers/admin/book\_controller.rb  
defined like this:

class Admin::BookController \< ApplicationController

Then the default route to the controller will be /admin/book. There  
is no need to add anything to routes.rb, it will “just work”.

---

<div class="post-metadata">

**Author:** ![antonaylward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@antonaylward](https://www.ruby-forum.com/u/antonaylward)\
**Post date:** [February 19, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/routing-and-namespace/86065/3 "2007-02-19T22:40:59Z")

</div>

Paul B. said the following on 02/19/2007 12:16 PM:

> If you have a controller in app/controllers/admin/book\_controller.rb  
> defined like this:
> 
> class Admin::BookController \< ApplicationController
> 
> Then the default route to the controller will be /admin/book. There  
> is no need to add anything to routes.rb, it will “just work”.

Ah.  
I see, that picks up on the default.

Now what about my custom application route, then.  
It is supposed to be

```
   http://localhost:3000/TheStoryofLitchfileld/ChapterOne

```

aka “:book/:chapter” and that goes to the book\_chapter\_controller.rb

There is path before it to indicate the namespace or the controller.

–  
Always do your best. What you plant now, you will harvest later.

- Og Mandino
