Routing for grouping controllers and avoid modules

Hello,
I have this code in my config/routes.rb file

ActionController::Routing::Routes.draw do |map|
map.supervisor ‘supervisor/:controller/:action/:id’
map.connect ‘:controller/:action/:id’
end

I try to group three or four controlles in the same URL path with
routing, avoinding the use of modules or controller namespaces.
All the other controllers will have an standard rails URL, matching the
last route.

It almost works.
Each incoming path is matched with the appropiated route.
The problem come with the URL generation functions.
supervisor_url(:controller => …, :action=> …) works well, I get the
expected URL, but url_for(:controller => …, :action=> …) for all the
standard controllers fails as is always matched for the first route. All
the generated urls follow the /supervisor/controller/action path.

How can I make for group only some of the controller in the first route.
the parameter :requirements => {:controller => “whatever”} will be a
solution for only one controller. I think.

Has anybody have an elegant solution (I mean DRY) for this?
Or I have to do a special rout for each controller?

Thanks

Juanma

Why avoid controller modules/namespaces? I use 'em, love 'em, and
haven’t had any problems with 'em.

Joe

Joe R. MUDCRAP-CE wrote:

Why avoid controller modules/namespaces? I use 'em, love 'em, and
haven’t had any problems with 'em.

Joe

Well, I think that all becomes more messy.
Besides, I usually follow the advises of people tha knows more than
I,(Mike C. in this case).

http://glu.ttono.us/articles/2006/08/30/guide-things-you-shouldnt-be-doing-in-rails

This is an extract of the article

"Putting Controllers in Namespaces

This is really more trouble than itâ??s worth. You run into all sorts of
crazy errors if you do this and youâ??ll be confused and frustrated.
Youâ??ll then ask other people about it and theyâ??ll either blow you off
for using namespaces with controllers or procede to get confused and
frustrated as well. Then youâ??ll say, â??I with I had listened to Kevin and
Chrisâ?. If you want /admin/some_controller as an URL thatâ??s fine. Use
the routing thatâ??s built into rails.

Juanma C. пиÑ?еÑ?:

All the other controllers will have an standard rails URL, matching the
last route.

I would do like this :

ActionController::Routing::Routes.draw do |map|
[‘foo’, ‘bar’, ‘baz’].each do |supervisor_controller|
map.connect “/supervisor/#{supervisor_controller}/:action/:id”,
:controller => supervisor_controller
end
map.connect ‘:controller/:action/:id’
end

Doing like that you have explicitly stated set of controllers that can
be mapped to by those urls. + no need to change any other logic or use
named routes.

Also, I wouldn’t leave CAPTURE_EM_ALL route at (the one at the end).

I’m a bit fear of controllers in modules, because you need to use
link_to with caution (haven’t you forgot to prefix all your controllers
with “/” in link_to params ?)

Or use map.public and public_url instead of map.connect and url_for.

Juanma C. wrote:

Joe R. MUDCRAP-CE wrote:

Why avoid controller modules/namespaces? I use 'em, love 'em, and
haven’t had any problems with 'em.

Joe

Well, I think that all becomes more messy.

I think they make things much neater!

Besides, I usually follow the advises of people tha knows more than
I,(Mike C. in this case).

Well, how about DHH then? I think he posted somewhat recently that the
core team is in no way, shape, or form AGAINST controller
modules/namespaces.

http://glu.ttono.us/articles/2006/08/30/guide-things-you-shouldnt-be-doing-in-rails

This is an extract of the article

"Putting Controllers in Namespaces

This is really more trouble than itâ??s worth. You run into all sorts of
crazy errors if you do this and youâ??ll be confused and frustrated.
Youâ??ll then ask other people about it and theyâ??ll either blow you off
for using namespaces with controllers or procede to get confused and
frustrated as well. Then youâ??ll say, â??I with I had listened to Kevin and
Chrisâ?. If you want /admin/some_controller as an URL thatâ??s fine. Use
the routing thatâ??s built into rails.

I asked them for specifics on problems, but never got a concrete answer.
I’ll stick to my own experience.

Joe

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs