# Named routes in admin namespace

**URL:** <https://www.ruby-forum.com/t/named-routes-in-admin-namespace/143842>\
**Category:** Rails\
**Created:** [July 23, 2008, 6:53am UTC](https://www.ruby-forum.com/t/named-routes-in-admin-namespace/143842 "2008-07-23T06:53:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![giorgio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cab0a1/32.png) [@giorgio](https://www.ruby-forum.com/u/giorgio)\
**Post date:** [July 23, 2008, 6:53am UTC](https://www.ruby-forum.com/t/named-routes-in-admin-namespace/143842/1 "2008-07-23T06:53:20Z")

</div>

Hi,

I have a controller Admin::Categories in folder controllers/admin

I have a views/admin/categories/index.html.erb which contains:  
\<%= link\_to ‘New category’, new\_category\_path %\>

now if my routes.rb contains:  
map.resources :categories

Then the generated url does not have /admin/ on the front ie it is:  
/categories/new which does not work as the controller is in /admin

If I do something that seems to be suggested in the comments in  
routes.rb ie:  
map.namespace :admin do |admin|  
admin.resources :categories  
end

I get:  
undefined local variable or method `new\_category\_path’ for  
#ActionView::Base:0xb6fb5854

How do I get these fancy named routes to work in the admin namepace?  
I could have bunged in :controller=\>‘categories’ , :action=\>‘new’  
However we are told that these named routes are smarter…?

Any help appreciated  
George

---

<div class="post-metadata">

**Author:** ![giorgio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cab0a1/32.png) [@giorgio](https://www.ruby-forum.com/u/giorgio)\
**Post date:** [July 23, 2008, 7:02am UTC](https://www.ruby-forum.com/t/named-routes-in-admin-namespace/143842/2 "2008-07-23T07:02:06Z")

</div>

If u want to get the url like admin/categories/new then change ur link  
as  
\<%= link\_to new\_admin\_category\_path(@admin) %\>

---

<div class="post-metadata">

**Author:** ![giorgio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cab0a1/32.png) [@giorgio](https://www.ruby-forum.com/u/giorgio)\
**Post date:** [July 23, 2008, 7:13am UTC](https://www.ruby-forum.com/t/named-routes-in-admin-namespace/143842/3 "2008-07-23T07:13:49Z")

</div>

Thanks for that.

\<%= link\_to new\_admin\_category\_path%\> (without the @admin)  
works.

However I dont want to change all the links in all the view files!  
You must be able to generate the scaffold and tell it that it is in  
Admin namespace so that it does it for you?

Otherwise I may as well just convert it  
to :controller,… :action… at least that is easy to read and  
understand.

Cheers  
George

---

<div class="post-metadata">

**Author:** ![giorgio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cab0a1/32.png) [@giorgio](https://www.ruby-forum.com/u/giorgio)\
**Post date:** [July 28, 2008, 12:03pm UTC](https://www.ruby-forum.com/t/named-routes-in-admin-namespace/143842/4 "2008-07-28T12:03:23Z")

</div>

> **[Rolling with Rails 2.0 - The First Full Tutorial - Part 1 | AkitaOnRails.com](https://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial)**
>
> for brazilians: click here.
> I am very happy to see that my Rails 2.0 Screencast was very well received. More than 1,500 unique visitors watched it...

This has a good tut… on rails 2.0 and specifically has examples of  
the namespace problem. I had the same issue and just found it.
