# Routing to controller inside module

**URL:** <https://www.ruby-forum.com/t/routing-to-controller-inside-module/52575>\
**Category:** Rails\
**Created:** [January 16, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/routing-to-controller-inside-module/52575 "2006-01-16T18:13:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Norman\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@Norman\_T](https://www.ruby-forum.com/u/Norman_T)\
**Post date:** [January 16, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/routing-to-controller-inside-module/52575/1 "2006-01-16T18:13:43Z")

</div>

Hey,

am i to stupid to find the information about how to route to a  
controller in a module? Maybe module support has gone!

The controller is under:  
app/controllers/admin/my\_controller.rb

The my\_controller.rb file looks like this:  
module Admin  
class MyController  
def index  
render :text =\> ‘Hello!’  
end  
end  
end

How does a route to all controllers under module Admin look like?  
map.connect ‘admin/:controller/:action/:id’, :module =\> ‘admin’

This one gives me a NameError ‘uninitialized constant  
DepartmentController’

I tested following with the same result:  
map.connect ‘admin/my\_controller/:action/:id’, :controller =\>  
‘admin/my\_controller’

Are controllers within modules still supported?

## Ciao, Norman

Norman T. - inlet media e.K.

Phone: +49 (0)40 / 43 25 10 81  
Fax: +49 (0)40 / 43 25 10 82

HollÃ¤ndische Reihe 31  
22765 Hamburg

> **[Norman Timmler](http://www.inlet-media.de)**
>
> Home of FLVTool2 and blog of Norman Timmler, a Ruby on Rails architect in Hamburg, Germany.

---

<div class="post-metadata">

**Author:** ![Norman\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@Norman\_T](https://www.ruby-forum.com/u/Norman_T)\
**Post date:** [January 16, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/routing-to-controller-inside-module/52575/2 "2006-01-16T18:46:54Z")

</div>

You probably want something more like this, in  
/app/controllers/admin/my\_controller.rb:

class Admin::MyController \< ApplicationController  
…  
end

Rails will create the Admin module using its own dark magicks. You  
shouldn’t need to touch the default controller route either.

- james

---

<div class="post-metadata">

**Author:** ![Norman\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@Norman\_T](https://www.ruby-forum.com/u/Norman_T)\
**Post date:** [January 17, 2006, 2:01am UTC](https://www.ruby-forum.com/t/routing-to-controller-inside-module/52575/3 "2006-01-17T02:01:10Z")

</div>

Am Montag, den 16.01.2006, 17:46 +0000 schrieb James A.:

> You probably want something more like this, in  
> /app/controllers/admin/my\_controller.rb:
> 
> class Admin::MyController \< ApplicationController  
> …  
> end
> 
> Rails will create the Admin module using its own dark magicks. You  
> shouldn’t need to touch the default controller route either.

Sorry, but i figured out a typing error caused the problem 😉

By the way,

class Admin:Mycontroller

and

module Admin  
class MyController

## are the same, with the only difference, that the first one only works if the module has been declared before.

Norman T.

## [http://blog.inlet-media.de](http://blog.inlet-media.de)

Norman T. - inlet media e.K.

Phone: +49 (0)40 / 43 25 10 81  
Fax: +49 (0)40 / 43 25 10 82

HollÃ¤ndische Reihe 31  
22765 Hamburg

> **[Norman Timmler](http://www.inlet-media.de)**
>
> Home of FLVTool2 and blog of Norman Timmler, a Ruby on Rails architect in Hamburg, Germany.

---

<div class="post-metadata">

**Author:** ![Norman\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@Norman\_T](https://www.ruby-forum.com/u/Norman_T)\
**Post date:** [January 17, 2006, 2:01am UTC](https://www.ruby-forum.com/t/routing-to-controller-inside-module/52575/4 "2006-01-17T02:01:11Z")

</div>

Am Montag, den 16.01.2006, 17:46 +0000 schrieb James A.:

> You probably want something more like this, in  
> /app/controllers/admin/my\_controller.rb:
> 
> class Admin::MyController \< ApplicationController  
> …  
> end
> 
> Rails will create the Admin module using its own dark magicks. You  
> shouldn’t need to touch the default controller route either.

Sorry, but i figured out a typing error caused the problem 😉

By the way,

class Admin:Mycontroller

and

module Admin  
class MyController

## are the same, with the only difference, that the first one only works if the module has been declared before.

Norman T.

## [http://blog.inlet-media.de](http://blog.inlet-media.de)

Norman T. - inlet media e.K.

Phone: +49 (0)40 / 43 25 10 81  
Fax: +49 (0)40 / 43 25 10 82

HollÃ¤ndische Reihe 31  
22765 Hamburg

> **[Norman Timmler](http://www.inlet-media.de)**
>
> Home of FLVTool2 and blog of Norman Timmler, a Ruby on Rails architect in Hamburg, Germany.
