This project is archived and is in readonly mode.
Routes: match ignores :conditions.
Reported by epochwolf | March 7th, 2010 @ 09:09 PM
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
Comments and changes to this ticket
-
epochwolf March 8th, 2010 @ 06:33 AM
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.
-
José Valim March 8th, 2010 @ 10:53 PM
- State changed from new to invalid
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>