Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Possible routing bug

#2862

When a catch all route for a specific method is configured and an invalid URL is requested instead of the expected ActionController::RoutingError we're seeing ActionController::MethodNotAllowed

An example of this is:
map.connect '*path', :controller => 'fixes', :action => 'options_for_mopd', :conditions => { :method => :options }

It seems that the conditions check is being done too late so instead of matching on the combination of the path and conditions instead its matching on the path and then checking the conditions, resulting in what I believe is an incorrect exception.

Reported by Steven Hartland · July 2nd, 2009 @ 10:53 AM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from new to invalid

    Rails specifically raises a MethodNotAllowed in this case to mirror the HTTP error codes http://en.wikipedia.org/wiki/List_of_HTTP_status_codes specifically, 405

    July 2nd, 2009 @ 06:18 PM

  2. Steven Hartland
    Steven Hartland

    I would be inclined to agree for a none wild card path, but with the current behaviour is impossible to catch the total wild card case for a specific method request, without effectively breaking standard 404 behaviour for the instance.

    It may be that an additional directive to the route, possibly within :conditions, could be used to indicate if a match to the rule but not the method should result in NotFound or MethodNotAllowed.

    An example of this could be:
    map.connect '*path', :controller => 'fixes', :action => 'options_for_mopd', :conditions => { :method => :options, :match_method => true }

    Either way it would be a good idea to make it clear in the docs of ActionController::Routing as the current statement:
    "With conditions you can define restrictions on routes." Indicates that conditions "restrict" the matching of a route, which is not the case; the route matches but is bypassed in a post filter by the condition, hence facilitating MethodNotAllowed / 405 functionaility, if the path matches but the method does not.

    For completeness if anyone reading this is looking for a workaround, you can do this by adding a second catch all route without a :method condition that generates 404 e.g
    map.nofile '*path', :controller => 'fixes', :action => 'do404'

    July 2nd, 2009 @ 09:15 PM