Forum: Ruby on Rails Controller Naming Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris B. (Guest)
on 2006-03-14 18:59
(Received via mailing list)
Is it possible to have controllers named the following?
/admin
/admin/user

If not, is there some way to get it to work with routes?

I want to have some actions at the url /admin/<action> and some at
/admin/user/<action> (obviously in admin/user controller).



Thanks!!!
Sean S. (Guest)
on 2006-03-14 19:08
(Received via mailing list)
On Mar 14, 2006, at 9:56 AM, Chris B. wrote:

> Is it possible to have controllers named the following?
> /admin
> /admin/user
>
> If not, is there some way to get it to work with routes?
>
> I want to have some actions at the url /admin/<action> and some at
> /admin/user/<action> (obviously in admin/user controller).

See the following for a good write-up on this...

<http://justinfrench.com/index.php?id=122>

-S
Thiago A. (Guest)
on 2006-03-14 21:35
(Received via mailing list)
On 3/14/06, Chris B. <removed_email_address@domain.invalid> wrote:
> Is it possible to have controllers named the following?
> /admin
> /admin/user

Sure. The first controller would be named Admin and the second one
Admin::User, actually a User controller class inside a module named
Admin.

However, just naming them correctly won't do, the default routing
mechanism will interpret /admin/user as the action 'user' from the
controller 'admin'. You can achieve what you want by tweaking your
routes, make sure to add something like this on the top of the
routes.rb file (it needs to be on top, so it matches at a higher
priority than the default route):

---------
  map.connect 'admin/user/:action',
              :controller => 'admin/user'
---------

Good luck,

Thiago A.
This topic is locked and can not be replied to.