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.

[PATCH] in routes.rb :conditions => {:method => :any} gives error

#2700

in routes.rb -

ActionController::Routing::Routes.draw do |map|
  map.good 'good', :controller => 'good', :conditions => {:method => :get}

map.bad 'bad', :controller => 'bad', :conditions => {:method => :any}




map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end

rake routes returns

good GET /good                              {:controller=>"good", :action=>"index"}

     /:controller/:action/:id
     /:controller/:action/:id(.:format)</code>



when bad is uncommented

rake aborted!
Invalid HTTP method specified in route conditions: {:method=>:any}

Reported by trevor · May 23rd, 2009 @ 06:18 PM

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

Activity

  1. qoobaa
    qoobaa

    Can't you just use:

    ActionController::Routing::Routes.draw do |map|
      map.good 'good', :controller => 'good', :conditions => {:method => :get}
      map.bad 'bad', :controller => 'bad'
      map.connect ':controller/:action/:id'
      map.connect ':controller/:action/:id.:format'
    end
    

    Does it make any sense to add a condition that matches every case?

    June 29th, 2009 @ 08:35 PM

  2. trevor
    trevor

    the documentation states "Takes a hash of #{action} => #{method}, where method is :get/:post/:put/:delete, an array of any of the previous, or :any if the method does not matter."

    i'm expecting consistent behavior, one way or the other.

    % grep -R ':any' r*
    resources.rb:    #   an array of any of the previous, or <tt>:any</tt> if the method does not matter.
    resources.rb:    #   map.resources :messages, :new => { :new => :any, :preview => :post }
    resources.rb:          options[:conditions][:method] = method unless method == :any
    routing/route.rb:          "%-6s %-40s %s" % [(conditions[:method] || :any).to_s.upcase, segs, requirements.inspect]
    routing.rb:  #   <tt>:get</tt>, <tt>:put</tt>, <tt>:delete</tt> and <tt>:any</tt>. The default value is <tt>:any</tt>,
    routing.rb:  #   <tt>:any</tt> means that any method can access the route.
    

    June 29th, 2009 @ 08:46 PM

  3. Frankie Roberto
    Frankie Roberto

    This seems does seem to be broken.

    Works for resources (:collection => {:test => :any}) but not for named paths.

    July 2nd, 2009 @ 01:53 PM

  4. anupom syam
    anupom syam
    • Tag set to patch, tested

    i think it's broken. i am adding a patch along with this ticket (with tests).

    July 14th, 2009 @ 06:47 PM

  5. anupom syam
    anupom syam
    • Title changed from in routes.rb :conditions => {:method => :any} gives error to [PATCH] in routes.rb :conditions => {:method => :any} gives error

    July 19th, 2009 @ 07:13 PM

  6. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from patch, tested to bugmash, patch, tested

    August 7th, 2009 @ 02:31 PM

  7. qmx
    qmx

    +1

    Apply cleanly to current stable.

    August 8th, 2009 @ 02:19 AM

  8. pjammer
    pjammer

    +1 I verified this patched worked for me in a mini app, as well as the tests passed.

    August 8th, 2009 @ 03:10 AM

  9. Derander
    Derander

    +1 verified. Applies cleanly to current stable & master.

    Tests pass for stable, and two tests fail on master. I do not believe they're related -- they're dealing w/ the textilize method.

    August 9th, 2009 @ 09:18 PM

  10. José Valim
    José Valim
    • State changed from new to wontfix
    • Tag changed from bugmash, patch, tested to patch, tested

    As Jakub pointed, you can already do that. We would just add more code to maintain.

    August 9th, 2009 @ 10:58 PM

  11. freerobby
    freerobby

    If you need a quick substitute, passing in nil in place of :any works as follows:
    :conditions => {:method => nil}

    January 4th, 2010 @ 10:31 PM