Hi, I have the following routes map.connect '':controller/:id/:action'', :id=>/4/, :defaults=>{ :action=>''show''} map.connect '':controller/:action'', :defaults=>{:action=>''index''} and when I point my browser to "localhost:3000/departments" I see an error because the show action cannot find a department with id=0. Why is the first route the one that is being used. I should be the second and I should see the index action''s results. Really what I want is :id=>/^\d+.*/ but I can''t even get the above example working. Any ideas? Thanks, Peter
Peter Michaux
2006-Jul-15 18:32 UTC
[Rails] Re: routing requirements broken in Rails 1.1.4?
Anyone? I''m totally stumped on this one. Thanks, Peter On 7/14/06, Peter Michaux <petermichaux@gmail.com> wrote:> Hi, > > I have the following routes > > map.connect '':controller/:id/:action'', :id=>/4/, :defaults=>{ :action=>''show''} > map.connect '':controller/:action'', :defaults=>{:action=>''index''} > > and when I point my browser to "localhost:3000/departments" I see an > error because the show action cannot find a department with id=0. Why > is the first route the one that is being used. I should be the second > and I should see the index action''s results. > > Really what I want is :id=>/^\d+.*/ but I can''t even get the above > example working. > > Any ideas? > > Thanks, > Peter >
Peter Michaux
2006-Jul-16 06:06 UTC
[Rails] Re: routing requirements broken in Rails 1.1.4?
Hi, I created a fresh rails app with 1.1.4 to try and solve my problem $ rails temp $ cd temp $ script/generate controller front index show I edited the routes.rb file to have only two routes map.connect '':controller/:id/:action'', :id=>/4/, :defaults=>{ :action=>''show''} map.connect '':controller/:action'', :defaults=>{:action=>''index''} When I type http://localhost:3000/front into my browser I see the show template. I thought I should see the index template. Is this expected behavior? Thanks, Peter
Rimantas Liubertas
2006-Jul-16 10:26 UTC
[Rails] Re: routing requirements broken in Rails 1.1.4?
<...>> I edited the routes.rb file to have only two routes > > map.connect '':controller/:id/:action'', :id=>/4/, :defaults=>{ :action=>''show''} > map.connect '':controller/:action'', :defaults=>{:action=>''index''} > > When I type http://localhost:3000/front into my browser I see the show > template. I thought I should see the index template. > > Is this expected behavior?Yes. :name => /regexp/ or :requirements => { :name => /regexp/ } work only on parameters provided in URL, so if you call http://localhost:3000/front first rule in you routes matches, assuming :id => nil and :action => show. The :id=>/4/ part is not used. Try http://localhost:3000/front/5/ and you will get error - because now :id is present in URL and it does not match /4/. Maybe you want something like this: map.connect '':controller/:action'', :action => /\D+/ map.connect '':controller/:id/:action'', :defaults =>{:action => ''show''}, :id => /\d+/ :defaults => { :action => ''index'' } is not necessary, because it is default by default :) Regards, Rimantas -- http://rimantas.com/
Peter Michaux
2006-Jul-16 17:42 UTC
[Rails] Re: routing requirements broken in Rails 1.1.4?
Hi Rimantas! On 7/16/06, Rimantas Liubertas <rimantas@gmail.com> wrote:> > I edited the routes.rb file to have only two routes > > > > map.connect '':controller/:id/:action'', :id=>/4/, :defaults=>{ :action=>''show''} > > map.connect '':controller/:action'', :defaults=>{:action=>''index''} > > > > When I type http://localhost:3000/front into my browser I see the show > > template. I thought I should see the index template. > > > > Is this expected behavior? > > Yes. :name => /regexp/ or :requirements => { :name => /regexp/ } work > only on parameters provided in URL, so if you call > http://localhost:3000/front first rule in you routes matches, > assuming :id => nil and :action => show. The :id=>/4/ part is not used.That is absolutely bizarre behavior to me. I made a point of saying that id must match ''4'' but if I don''t include a 4 in the URL then it works ok as nil. Imagine that policy for a username/password form. The password must be "abracadabra" but nil is ok too. Anyway, thanks for the information. This has been driving me nuts. Peter