# Noob Subdirectory Question

**URL:** <https://www.ruby-forum.com/t/noob-subdirectory-question/121566>\
**Category:** Rails\
**Created:** [November 28, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/noob-subdirectory-question/121566 "2007-11-28T23:19:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emarthinsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/91b2a8/32.png) [@emarthinsen](https://www.ruby-forum.com/u/emarthinsen)\
**Post date:** [November 28, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/noob-subdirectory-question/121566/1 "2007-11-28T23:19:39Z")

</div>

Hi-

I’m new to RoR (as probably evidenced by this post). What I want to do  
is group some controllers beneath a subdirectory. For instance, I want  
to have a [http://www.mysite.com/admin](http://www.mysite.com/admin) section of the site that has  
areas for managing users, products, etc. using URLs like  
[http://www.mysite.com/admin/user/new](http://www.mysite.com/admin/user/new) and so on. My question is  
twofold. First, what is the best way to do this? Second, is this the  
RoR way to do things or am I thinking in the paradigm of more  
traditionla web frameworks.

Regards-  
Eric

P.S. - Sorry if this question has been answered. Searhcing for  
“directory” and “subdirectory” gives noisy results.

---

<div class="post-metadata">

**Author:** ![emarthinsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/91b2a8/32.png) [@emarthinsen](https://www.ruby-forum.com/u/emarthinsen)\
**Post date:** [November 28, 2007, 11:24pm UTC](https://www.ruby-forum.com/t/noob-subdirectory-question/121566/2 "2007-11-28T23:24:54Z")

</div>

On Nov 28, 2007 4:19 PM, emarthinsen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m new to RoR (as probably evidenced by this post). What I want to do  
> is group some controllers beneath a subdirectory. For instance, I want  
> to have a [http://www.mysite.com/admin](http://www.mysite.com/admin) section of the site that has  
> areas for managing users, products, etc. using URLs like  
> [http://www.mysite.com/admin/user/new](http://www.mysite.com/admin/user/new) and so on. My question is  
> twofold. First, what is the best way to do this? Second, is this the  
> RoR way to do things or am I thinking in the paradigm of more  
> traditionla web frameworks.

You can create routes to make the urls appear however you want, no  
sub-directories required.

Have a look at [Peak Obsession](http://manuals.rubyonrails.com/read/chapter/65)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![emarthinsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/91b2a8/32.png) [@emarthinsen](https://www.ruby-forum.com/u/emarthinsen)\
**Post date:** [November 29, 2007, 1:08pm UTC](https://www.ruby-forum.com/t/noob-subdirectory-question/121566/3 "2007-11-29T13:08:31Z")

</div>

You can do this nicely & transparently in Rails:

# file: app/controllers/admin/users\_controller.rb

class Admin::UsersController \< ApplicationController  
end

Then:

url\_for( :controller =\> ‘admin/users’, :action =\> ‘new’ )  
=\> …/admin/users/new

Ie:

1. You put your controller in a subdirectory ‘admin’ in ‘app/  
controllers’ directory
2. You namespace the controller (Admin::UsersController)
3. You put your views in corresponding directory (app/views/admin/  
users) – but you don’t have to
4. Don’t forget to use correct syntaxt in url\_for, link\_to, render  
(eg. render :template =\> ‘admin/new’)

Cheers,

Karel

P.S.  
You can even subclass your Admin::UsersController from your “default”  
or “presentation layer” UsersController and use inheritance this way.
