# Routing namespaced controllers

**URL:** <https://www.ruby-forum.com/t/routing-namespaced-controllers/177527>\
**Category:** Rails\
**Created:** [October 19, 2009, 8:16pm UTC](https://www.ruby-forum.com/t/routing-namespaced-controllers/177527 "2009-10-19T20:16:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bakkhoz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d6d6ee/32.png) [@bakkhoz](https://www.ruby-forum.com/u/bakkhoz)\
**Post date:** [October 19, 2009, 8:16pm UTC](https://www.ruby-forum.com/t/routing-namespaced-controllers/177527/1 "2009-10-19T20:16:09Z")

</div>

Hi,

I have one controller in the /app/controllers/animals\_controller.rb  
directory, and another in  
/app/controllers/production/services\_controller.rb. The thing is that  
one Animal has many Services, and i’d like to access to them using  
something like:

[http://localhost:3000/animals/1/production/services/1](http://localhost:3000/animals/1/production/services/1)

or at least with:

[http://localhost:3000/animals/1/services/1](http://localhost:3000/animals/1/services/1)

I tried the last one adding in routes.rb:

map.resources :animals, :has\_many =\> :services

but it throws me an error: uninitialized constant ServicesController

any idea?

Thanks.

---

<div class="post-metadata">

**Author:** ![bakkhoz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d6d6ee/32.png) [@bakkhoz](https://www.ruby-forum.com/u/bakkhoz)\
**Post date:** [October 19, 2009, 8:29pm UTC](https://www.ruby-forum.com/t/routing-namespaced-controllers/177527/2 "2009-10-19T20:29:13Z")

</div>

On Mon, Oct 19, 2009 at 11:16 AM, Sergio Aristizabal \<  
removed\_email\_address@domain.invalid\> wrote:

> any idea?
> 
> Thanks.

Your ServicesController is in a non-standard location. Thus, what’s the  
reasoning for having ServicesController within the production directory?  
In any case, you should be able to do the following:

config.load\_paths += %W( #{RAILS\_ROOT}/app/controllers/production )

The above adds the production directory to your load path.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![bakkhoz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d6d6ee/32.png) [@bakkhoz](https://www.ruby-forum.com/u/bakkhoz)\
**Post date:** [October 19, 2009, 8:31pm UTC](https://www.ruby-forum.com/t/routing-namespaced-controllers/177527/3 "2009-10-19T20:31:33Z")

</div>

On Mon, Oct 19, 2009 at 11:27 AM, Conrad T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > something like:
> 
> config.load\_paths += %W( #{RAILS\_ROOT}/app/controllers/production )

BTW, the above line goes into your environment.rb file within the  
Rails::Initializer  
block.

-Conrad

---

<div class="post-metadata">

**Author:** ![bakkhoz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d6d6ee/32.png) [@bakkhoz](https://www.ruby-forum.com/u/bakkhoz)\
**Post date:** [October 20, 2009, 7:06pm UTC](https://www.ruby-forum.com/t/routing-namespaced-controllers/177527/4 "2009-10-20T19:06:18Z")

</div>

‘production/services’ should work as the controller name. The  
“non-standard location” should not be an issue. In my app i dont need  
that init line.

2009/10/19, Conrad T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > /app/controllers/production/services\_controller.rb. The thing is that
> > 
> > reasoning for having ServicesController within the production directory?
> 
> > > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > > 
> > > > >
> 
> >

–  
Von meinen Mobilgerät aus gesendet
