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.
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/.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.