# 2 RESTful controllers for the same resource

**URL:** <https://www.ruby-forum.com/t/2-restful-controllers-for-the-same-resource/176419>\
**Category:** Rails\
**Created:** [September 30, 2009, 9:44am UTC](https://www.ruby-forum.com/t/2-restful-controllers-for-the-same-resource/176419 "2009-09-30T09:44:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PanosJee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@PanosJee](https://www.ruby-forum.com/u/PanosJee)\
**Post date:** [September 30, 2009, 9:44am UTC](https://www.ruby-forum.com/t/2-restful-controllers-for-the-same-resource/176419/1 "2009-09-30T09:44:05Z")

</div>

Hi everyone I want to have two restful controllers for the same  
resource (Users)  
One controller (UsersController) is straight in the controllers folder  
and is used for singup and so on  
Then i need another controller for users which is inside an admin  
folder (Admin::UsersController)

In my routes.rb i have

map.resources :users

# Sample resource route within a namespace:

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

When i access the /admin/users it will render the index action of the  
UsersController not the Admin::UsersController  
Any clues?

---

<div class="post-metadata">

**Author:** ![PanosJee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@PanosJee](https://www.ruby-forum.com/u/PanosJee)\
**Post date:** [October 1, 2009, 3:24am UTC](https://www.ruby-forum.com/t/2-restful-controllers-for-the-same-resource/176419/2 "2009-10-01T03:24:22Z")

</div>

PanosJee wrote:

> Hi everyone I want to have two restful controllers for the same  
> resource (Users)  
> One controller (UsersController) is straight in the controllers folder  
> and is used for singup and so on  
> Then i need another controller for users which is inside an admin  
> folder (Admin::UsersController)

Take a look at the following:

> **[Rails Routing from the Outside In — Ruby on Rails Guides](https://guides.rubyonrails.org/routing.html#namespaced-resources)**
>
> Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred...

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

$ rake routes  
users GET /users(.:format)  
{:action=\>“index”, :controller=\>“users”}  
POST /users(.:format)  
{:action=\>“create”, :controller=\>“users”}  
new\_user GET /users/new(.:format) {:action=\>“new”,  
:controller=\>“users”}  
edit\_user GET /users/:id/edit(.:format) {:action=\>“edit”,  
:controller=\>“users”}  
user GET /users/:id(.:format) {:action=\>“show”,  
:controller=\>“users”}  
PUT /users/:id(.:format)  
{:action=\>“update”, :controller=\>“users”}  
DELETE /users/:id(.:format)  
{:action=\>“destroy”, :controller=\>“users”}  
admin\_users GET /admin/users(.:format)  
{:action=\>“index”, :controller=\>“admin/users”}  
POST /admin/users(.:format)  
{:action=\>“create”, :controller=\>“admin/users”}  
new\_admin\_user GET /admin/users/new(.:format) {:action=\>“new”,  
:controller=\>“admin/users”}  
edit\_admin\_user GET /admin/users/:id/edit(.:format) {:action=\>“edit”,  
:controller=\>“admin/users”}  
admin\_user GET /admin/users/:id(.:format) {:action=\>“show”,  
:controller=\>“admin/users”}  
PUT /admin/users/:id(.:format)  
{:action=\>“update”, :controller=\>“admin/users”}  
DELETE /admin/users/:id(.:format)  
{:action=\>“destroy”, :controller=\>“admin/users”}
