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 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.
Regards-
Eric
P.S. - Sorry if this question has been answered. Searhcing for
“directory” and “subdirectory” gives noisy results.
On Nov 28, 2007 4:19 PM, emarthinsen [email protected] 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 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.
You can create routes to make the urls appear however you want, no
sub-directories required.
Have a look at Peak Obsession
–
Greg D.
http://destiney.com/
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:
- You put your controller in a subdirectory ‘admin’ in ‘app/
controllers’ directory
- You namespace the controller (Admin::UsersController)
- You put your views in corresponding directory (app/views/admin/
users) – but you don’t have to
- 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.