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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Joe Ruby MUDCRAP-CE
2006-Sep-27 22:56 UTC
Re: Routing for grouping controllers and avoid modules
Why avoid controller modules/namespaces? I use ''em, love ''em, and haven''t had any problems with ''em. Joe -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Juanma Cervera
2006-Sep-27 23:13 UTC
Re: Routing for grouping controllers and avoid modules
Joe Ruby MUDCRAP-CE wrote:> Why avoid controller modules/namespaces? I use ''em, love ''em, and > haven''t had any problems with ''em. > > JoeWell, I think that all becomes more messy. Besides, I usually follow the advises of people tha knows more than I,(Mike Clark 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. ============================================================= -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Joe Ruby MUDCRAP-CE
2006-Sep-27 23:23 UTC
Re: Routing for grouping controllers and avoid modules
Juanma Cervera wrote:> Joe Ruby 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 Clark 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Juanma Cervera пишет:> 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. >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 ?) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Ashley Thomas
2006-Sep-28 13:24 UTC
Re: Routing for grouping controllers and avoid modules
Or use map.public and public_url instead of map.connect and url_for. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---