# Mapping a resource to a subdirectory controller

**URL:** <https://www.ruby-forum.com/t/mapping-a-resource-to-a-subdirectory-controller/178377>\
**Category:** Rails\
**Created:** [November 3, 2009, 7:33pm UTC](https://www.ruby-forum.com/t/mapping-a-resource-to-a-subdirectory-controller/178377 "2009-11-03T19:33:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark42](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/65b543/32.png) [@mark42](https://www.ruby-forum.com/u/mark42)\
**Post date:** [November 3, 2009, 7:33pm UTC](https://www.ruby-forum.com/t/mapping-a-resource-to-a-subdirectory-controller/178377/1 "2009-11-03T19:33:26Z")

</div>

My app (like so many others) has an admin section, which uses  
controllers inside an admin directory. To keep it simple, I’m only  
administering the User resource for now. I have a controller that  
looks like this:

`
class Admin::UsersController < ApplicationController
  # normal scaffold methods in here
end
`

I’ve also added the following lines to my routes.rb file:

`
map.namespace :admin do |admin|
  admin.resources :users
end
`

In my admin/users/index view, I’d like to be able to use link\_to to  
create a delete link for each user. If I wasn’t using subdirectories,  
it would be like this:

`
<%= link_to "Delete", user, :confirm => "Are you sure?", :method
=> :delete %>
`

When I put this code in admin/users/index, it links to the regular  
users section (not the admin one), which has no destroy method. How  
can I make this link to the admin version? Do I need to hardcode the  
URL into the link\_to method, or is there a cleaner way that I don’t  
know about?

Thanks  
-Jake

---

<div class="post-metadata">

**Author:** ![mark42](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/65b543/32.png) [@mark42](https://www.ruby-forum.com/u/mark42)\
**Post date:** [November 3, 2009, 7:37pm UTC](https://www.ruby-forum.com/t/mapping-a-resource-to-a-subdirectory-controller/178377/2 "2009-11-03T19:37:33Z")

</div>

P.S. Sorry about the ` tags. I was hoping they’d work, but I
guess not. Hopefully their intent is clear.`

---

<div class="post-metadata">

**Author:** ![mark42](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/65b543/32.png) [@mark42](https://www.ruby-forum.com/u/mark42)\
**Post date:** [November 4, 2009, 6:26am UTC](https://www.ruby-forum.com/t/mapping-a-resource-to-a-subdirectory-controller/178377/3 "2009-11-04T06:26:16Z")

</div>

Figured it out. The correct code for each resource action is:

\<%= link\_to “Index”, admin\_users\_path %\>  
\<%= link\_to “Show”, admin\_user\_path(user) %\>  
\<%= link\_to “Edit”, edit\_admin\_user\_path(user) %\>  
\<%= link\_to “Delete”, admin\_user\_path(user), :confirm =\> “Are you  
sure?”, :method =\> :delete %\>

The users/user thing was throwing me off.
