Forum: Ruby on Rails Routes

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.
98872bd7af9f6b8238bfa06d784cf6a7?d=identicon&s=25 Gros Gros (gros)
on 2005-12-13 19:37
Hello,

Let's call my first controller "admin"
It's my main administration controller

My second controller is called "admin/category"
I use this controller to manage my categories on the admin side.

Now if I enter the following url
"http://localhost:3000/admin/category/list"
I encounter an error because rails tries to use the default route
  map.connect ':controller/:action/:id'
and tries to match with the "admin" controller and the action "category"
and the id "list".

I think this behaviour is not normal because in the "admin" controller
there is no "category" action.
I'd like rails to find by itself the controller "admin/category" and
call the "list" action.

In the present case i'm forced to define a new route
  map.connect 'admin/category/:action/:id', :controller =>
'admin/category'

If i had no "admin" controller but only a "admin/category" controller it
works with default route.

I'm i right ? or is there some configuration trick i didn't noticed ?
Cb610750ee94ca103aef4b2dc7b1b768?d=identicon&s=25 Nick Stuart (Guest)
on 2005-12-13 20:18
(Received via mailing list)
One way to get around this is to do the following. Keep your category
controller as it is, but make the 'admin' controller into something
like 'admin/main' or the like.

Then, in your routes add something like:
map.connect "/admin/", :controller => "admin/main", :action => "index"

which will allow you just type in /admin/ and get to the index. I have
my site set up this way, and it works well because I really only use
the index action on this controller anyways.

Hope this helps!
-Nick
A2b2f4ee23989dc68529baef9cbddcd6?d=identicon&s=25 Julian 'Julik' Tarkhanov (Guest)
on 2005-12-13 20:21
(Received via mailing list)
On 13-dec-2005, at 19:37, gros gros wrote:

> I encounter an error because rails tries to use the default route
> In the present case i'm forced to define a new route
>   map.connect 'admin/category/:action/:id', :controller =>
> 'admin/category'
>
> If i had no "admin" controller but only a "admin/category"
> controller it
> works with default route.
>
> I'm i right ? or is there some configuration trick i didn't noticed ?

I guess there is. If you put controllers in subdirectories you have
to namespace them.

'/admin' :controller=>'admin/main'

for Admin::MainController

and further on it will pick them automatically

Admin::CategoriesController and so on and so forth
98872bd7af9f6b8238bfa06d784cf6a7?d=identicon&s=25 Gros Gros (gros)
on 2005-12-14 09:23
Ok thank you all, so i'll create something like 'admin/main' :/
This topic is locked and can not be replied to.