Hello, I''m trying to play with routes but I''m stuck with something ... The following route allows me to map nice urls to a content : map.content '':category/:content'', :controller => "home", :action => "show" but this route has a draw back, I can''t access anymore to given parts of my app as ''admin/content'' or ''admin/category'' because these urls match my content route. So my question is, how can I skip this route when my url begins with ''admin'' ? Thanks in advance. -- Nicolas Cavigneaux http://www.bounga.org http://www.cavigneaux.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
try putting it lower in the list. routes match the first one found in the list, so if '':category/:content'' is above ''admin/content'' then it''s always going to match and ''admin/content'' will never be seen. Chris On 1/6/07, Nicolas Cavigneaux <nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org> wrote:> > Hello, > > I''m trying to play with routes but I''m stuck with something ... > > The following route allows me to map nice urls to a content : > > map.content '':category/:content'', :controller => "home", :action => > "show" > > but this route has a draw back, I can''t access anymore to given parts > of my app as ''admin/content'' or ''admin/category'' because these urls > match my content route. > > So my question is, how can I skip this route when my url begins with > ''admin'' ? > > Thanks in advance. > -- > Nicolas Cavigneaux > http://www.bounga.org > http://www.cavigneaux.net > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Le 6 janv. 07 à 18:55, Chris Hall a écrit :> > try putting it lower in the list. routes match the first one found in > the list, so if '':category/:content'' is above ''admin/content'' then > it''s always going to match and ''admin/content'' will never be seen.Yes, I know but I''ve just have this : map.home '''', :controller => "home" map.content '':category/:content'', :controller => "home", :action => "show" # Install the default route as the lowest priority. map.connect '':controller/:action/:id'' so I can''t lower it and I can''t find a requirement that do what I want ... I tried something like : map.admin ''admin/:action'', :controller => "admin/#{:action}" but it doesn''t work ... and I don''t want to create a route for each section (module) of my admin area ... Any idea ? -- Nicolas Cavigneaux http://www.bounga.org http://www.cavigneaux.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
you shouldn''t have to create a route for each module in your admin area map.admin ''admin/:action'', :controller => ''admin'' should be enough. put it between map.home and map.content routes so when rails sees anything beginning with admin it will route to the admin controller and whatever is in the :action param will map to a method in the controller ie ''admin/users'' # controller = ''admin'', action = ''users'' ''admin/content'' # controller = ''admin'', action = ''content'' Chris On 1/6/07, Nicolas Cavigneaux <nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org> wrote:> > > Le 6 janv. 07 à 18:55, Chris Hall a écrit : > > > > > try putting it lower in the list. routes match the first one found in > > the list, so if '':category/:content'' is above ''admin/content'' then > > it''s always going to match and ''admin/content'' will never be seen. > > > Yes, I know but I''ve just have this : > > map.home '''', :controller => "home" > map.content '':category/:content'', :controller => "home", :action > => "show" > > # Install the default route as the lowest priority. > map.connect '':controller/:action/:id'' > > so I can''t lower it and I can''t find a requirement that do what I > want ... > > I tried something like : > > map.admin ''admin/:action'', :controller => "admin/#{:action}" > > but it doesn''t work ... and I don''t want to create a route for each > section (module) of my admin area ... > > Any idea ? > -- > Nicolas Cavigneaux > http://www.bounga.org > http://www.cavigneaux.net > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Le 6 janv. 07 à 19:15, Chris Hall a écrit :> > you shouldn''t have to create a route for each module in your admin > area > > map.admin ''admin/:action'', :controller => ''admin'' > > should be enough.It can''t work because ''admin/content'' or ''admin/category'' are controllers because I''m using this : class Admin::ContentController < Admin::BaseController The only way I can find is to write a route for each module, eg: map.admin_content ''admin/content'', : controller => ''admin/content'' It''s a bit strange to do that ... -- Nicolas Cavigneaux http://www.bounga.org http://www.cavigneaux.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
So my routes.rb is like that : ActionController::Routing::Routes.draw do |map| map.home '''', :controller => "home" # Admin routes map.connect ''admin/category'', :controller => ''admin/category'' map.connect ''admin/content'', :controller => ''admin/content'' map.connect ''admin/definition'', :controller => ''admin/definition'' map.connect ''admin/file'', :controller => ''admin/file'' map.connect ''admin/layout'', :controller => ''admin/layout'' # Content route map.content '':category/:content'', :controller => "home", :action => "show" # Install the default route as the lowest priority. map.connect '':controller/:action/:id'' end It''s so ugly ... Any idea ? -- Nicolas Cavigneaux http://www.bounga.org http://www.cavigneaux.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
unfortunately when using controllers that way, I don''t think there is any way to setup routes any differently. perhaps someone else on the list has some additional insight. one potential problem would be if someone tried to access an admin route that did not exist, such as /admin/whatever''. it would not match any of your defined admin routes and would then pass to '':category/:content'' which would be routed to ''home/show''...something to watch for. i think one additional route to catch anything else. ''admin/:missing'' might be needed and could be routed to a 404 page or something. keep in mind that you''re not going to be editing routes much. so while you might consider it ugly, it''s only in the routes.rb file and not the rest of your code. you might want to go one extra step and use named routes as that will make the rest of your code a bit prettier. ie map.category_admin ''admin/category'', :controller => ''admin/category'' then any link to that will be link_to "Category Admin", category_admin_url, ... rather than link_to "Category Admin", :controller => "admin/category" On 1/8/07, Nicolas Cavigneaux <nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org> wrote:> > So my routes.rb is like that : > > ActionController::Routing::Routes.draw do |map| > map.home '''', :controller => "home" > > # Admin routes > map.connect ''admin/category'', :controller => ''admin/category'' > map.connect ''admin/content'', :controller => ''admin/content'' > map.connect ''admin/definition'', :controller => ''admin/definition'' > map.connect ''admin/file'', :controller => ''admin/file'' > map.connect ''admin/layout'', :controller => ''admin/layout'' > > # Content route > map.content '':category/:content'', :controller => "home", :action > => "show" > > # Install the default route as the lowest priority. > map.connect '':controller/:action/:id'' > end > > It''s so ugly ... > > Any idea ? > -- > Nicolas Cavigneaux > http://www.bounga.org > http://www.cavigneaux.net > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Nicolas :> So my routes.rb is like that : > > ActionController::Routing::Routes.draw do |map| > map.home '', :controller => "home" > > # Admin routes > map.connect 'admin/category', :controller => 'admin/category' > map.connect 'admin/content', :controller => 'admin/content' > map.connect 'admin/definition', :controller => 'admin/definition' > map.connect 'admin/file', :controller => 'admin/file' > map.connect 'admin/layout', :controller => 'admin/layout' > > # Content route > map.content ':category/:content', :controller => "home", :action > => "show" > > # Install the default route as the lowest priority. > map.connect ':controller/:action/:id' > end > > It's so ugly ...Have you tried : map.connect 'admin/:controller/:action/:id' -- Jean-Franois. -- la renverse. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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?hl=en -~----------~----~----~----~------~----~------~--~---
Le 8 janv. 07 à 14:29, Jean-François a écrit :> Have you tried : > > map.connect ''admin/:controller/:action/:id''Yes but it doesn''t work. -- Nicolas Cavigneaux http://www.bounga.org http://www.cavigneaux.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Le 8 janv. 07 à 14:19, Chris Hall a écrit :> > unfortunately when using controllers that way, I don''t think there is > any way to setup routes any differently. perhaps someone else on the > list has some additional insight.Ok, thank you for help :-) -- Nicolas Cavigneaux http://www.bounga.org http://www.cavigneaux.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---