This project is archived and is in readonly mode.

#2151 ✓stale
John Small

routing not recognizing requirements for :format

Reported by John Small | March 6th, 2009 @ 02:55 PM | in 2.3.4

This is similar to ticket 2043, which was resolved a few days ago. I have the patch to solve that problem in my source code from a recent downloaded and still have the following problem;-

Use case I've switched from IIS to RoR and changed all my url endings and also file names to be SEO friendly, but Google and hundreds of external links pointing to us are sending me requests with the old file names and old extensions.

Easy solution I define a route which maps every request for a url ending in .htm to an action which works out which new url to redirect the request to. This works in Rails versions up to 2.2.2 but now fails in 2.3.1

Example routes

map.public_view ':id.:format', 
            :controller => 'public_view',
            :action =>'territory_listing',
            :requirements => { :method =>'get',  :format =>/html/i}

map.public_view ':id.:format', # aliasing from old style
            :controller => 'public_view',
            :action =>'redirect_from_old',
            :requirements => { :method =>'get',  :format =>/htm/i} # old style pages ended with htm

My test which now fails is

assert_recognizes({:controller => "public_view",
                     :action =>"redirect_from_old",
                     :id=>'Budget Flights'},
                     "/Budget Flights.htm",{},"/Budget Flights.htm not recognised")

It's picking up the action from the prior route, i.e 'territory_listing' which has requirements :format =>/html/i

In fact I can change /html/i to /htjjjjjml/l and it'll still pick that route. So the routing is not testing requirements properly at least for :format =>/something/

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by