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 section of the site that has
areas for managing users, products, etc. using URLs like
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.
P.S. - Sorry if this question has been answered. Searhcing for
"directory" and "subdirectory" gives noisy results.
You can create routes to make the urls appear however you want, no
Have a look at Peak Obsession
You can do this nicely & transparently in Rails:
# file: app/controllers/admin/users_controller.rb
class Admin::UsersController < ApplicationController
url_for( :controller => 'admin/users', :action => 'new' )
1. You put your controller in a subdirectory 'admin' in 'app/
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
3. Don't forget to use correct syntaxt in url_for, link_to, render
(eg. render :template => 'admin/new')
You can even subclass your Admin::UsersController from your "default"
or "presentation layer" UsersController and use inheritance this way.