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.

Routes: match ignores :conditions.

#4126

On a clean rails 3.0.0-beta application the routing command match ignores the :conditions hash if it is given. (Does not affect resource(s))

I used the following code in a cleanly build application to test this. (Needed to remove protect_from_forgery from ApplicationController)

Routes

    root :to => "home#index"
    match "get", :to => "home#get", :conditions => {:method => :get}
    match "post", :to => "home#post", :conditions => {:method => :post}

HomeController

    class HomeController < ApplicationController
      def index
        render :text => "index\n"
      end
  
      def get
        if request.get?
          render :text => "get\n"
        else
          render :text => "not_get\n"
        end
      end
  
      def post
        if request.get?
          render :text => "get\n"
        else
          render :text => "not_get\n"
        end
      end
    end

Tests

    user@host:~$ curl http://localhost:3001/get
    get
    user@host:~$ curl -F 'field=1' localhost:3001/get
    not_get
    user@host:~$ curl http://localhost:3001/post
    get
    user@host:~$ curl -F 'field=1' localhost:3001/post
    not_get

Reported by epochwolf · March 7th, 2010 @ 09:09 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. epochwolf
    epochwolf

    I think I figured out the problem. After poking around the rails source it looks like http://guides.rails.info/routing.html#route-conditions is out of date. It shows

        match 'photo/:id' => 'photos#show', :conditions => { :method => :get }
    

    when the proper way to do this according to the edge source is

        get 'photo/:id' => 'photos#show'
    

    I assume match doesn't allow :conditions by design. If so, could someone close this ticket.

    March 8th, 2010 @ 06:33 AM

  2. José Valim
    José Valim
    • State changed from new to invalid

    March 8th, 2010 @ 10:53 PM