# Namespaces and routing

**URL:** <https://www.ruby-forum.com/t/namespaces-and-routing/129094>\
**Category:** Rails\
**Created:** [February 14, 2008, 7:24am UTC](https://www.ruby-forum.com/t/namespaces-and-routing/129094 "2008-02-14T07:24:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [February 14, 2008, 7:24am UTC](https://www.ruby-forum.com/t/namespaces-and-routing/129094/1 "2008-02-14T07:24:29Z")

</div>

I’m creating a restful (for the most part) website that is read-only  
from a user perspective, but has an admin section where content is  
generated. I would like to do something like the following for this  
admin portion:

[http://www.mysite.com/admin/[controller]](http://www.mysite.com/admin/%5Bcontroller%5D)

I’ve ran into several stumbling blocks and after 2 days, have not found  
a solution. I started by creating a namespace.

map.namespace(:admin) do |admin|  
admin.resources :categories  
admin.resources :sections  
admin.resources :items  
end

I then used these commands to generate the right resources:

script/generate resource admin/category title:string  
script/generate resource admin/section title:string category:references  
script/generate resource admin/item title:string, section:references

Using this approach, I had controllers, models, and views created in an  
‘admin’ directory within each appropriate folder. Few questions so  
far…

(1) Having namespaced models seems like a bad practice. Yet, when I  
reconfigure them to not be namespaced, other resource routing fails such  
as creating a link like:

\<% for category in @categories %\>  
\<%= link\_to “show category” category %\>  
\<% end %\>

(2) When trying to run functional tests on controllers within the  
‘admin’ namespace, I get all kinds of errors. Since the fixtures are in  
‘admin/’ within the ‘test’ directory, Rails doesn’t know to  
look there. I’ve found no way to configure that and moving it outside  
the ‘admin’ only makes the problem worse. So despite my user interface  
working, I cannot write any tests to validate it in this configuration.

I could really use some help, this issue is now breaching about 2 days  
of effort with no results. Has anyone had similar problems or can anyone  
offer some potential strategies to make this work?

I really appreciate anyons help. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [February 14, 2008, 7:50am UTC](https://www.ruby-forum.com/t/namespaces-and-routing/129094/2 "2008-02-14T07:50:59Z")

</div>

There is a screencast on this topic at

[Http://www.rubyplus.org](Http://www.rubyplus.org)  
Free Ruby & Rails screencasts

On Feb 13, 2008, at 10:24 PM, Dave A.  
\<removed\_email\_address@domain.invalid
