Forum: Ruby on Rails routing

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.
6738e5c4f17822f7e163ba938344755d?d=identicon&s=25 Daniel (Guest)
on 2006-04-10 17:36
I have this in my routes.rb:

...
map.connect ":action/:id", :controller => "default_controller"
..


It worked nicely, until I added a second controller to my project. The
new (second) controller is "Admin".

The problem is I cant reach the actions in the second controller.

http://mysite.com/some_action is routed to some_action in
default_controller. That is how I want it to be. But how do I reach
admin_action in the Admin controller? This doesnt work, for obvious
reasons:

http://mysite.com/admin/some_action

it gets routed to the undefined action admin in default_controller with
id some_action.

How can I correct this so that

http://mysite.com/some_action is routed to to
default_controller/some_action and
http://mysite.com/admin/admin_action is routed to
admin_controller/admin_action

???

Please help me!

Daniel
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2006-04-10 18:49
Daniel wrote:
> I have this in my routes.rb:
>
> ...
> map.connect ":action/:id", :controller => "default_controller"
> ..
>
>
> It worked nicely, until I added a second controller to my project. The
> new (second) controller is "Admin".
>
> The problem is I cant reach the actions in the second controller.
>
> http://mysite.com/some_action is routed to some_action in
> default_controller. That is how I want it to be. But how do I reach
> admin_action in the Admin controller? This doesnt work, for obvious
> reasons:
>
> http://mysite.com/admin/some_action
>
> it gets routed to the undefined action admin in default_controller with
> id some_action.
>
> How can I correct this so that
>
> http://mysite.com/some_action is routed to to
> default_controller/some_action and
> http://mysite.com/admin/admin_action is routed to
> admin_controller/admin_action

Routes are processed in the order they're given in routes.rb, so if you
want to trap the admin controller, give it a route BEFORE the one
definining "
/:action', :controller => 'default_controller'" etc.

Above that one, put:

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

Put the most specific entries first, and the most general ones at the
bottom.  That way you can trap the special cases before they're resolved
by the general default case.

Jeff
This topic is locked and can not be replied to.