Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Modify routing so that you can say :require => { :method => :post } f…
…or a route, and the route will never be selected unless the request method is POST. Only works for route recognition, not for route generation.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4209 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed Apr 13, 2006
1 parent c71607e commit 7a8883e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Modify routing so that you can say :require => { :method => :post } for a route, and the route will never be selected unless the request method is POST. Only works for route recognition, not for route generation. [Jamis Buck]

* Added :add_headers option to verify which merges a hash of name/value pairs into the response's headers hash if the prerequisites cannot be satisfied. [Sam Stephenson]
ex. verify :only => :speak, :method => :post,
:render => { :status => 405, :text => "Must be post" },
Expand Down
17 changes: 12 additions & 5 deletions actionpack/lib/action_controller/routing.rb
Expand Up @@ -306,6 +306,7 @@ def initialize(path, options = {})
initialize_components path
defaults, conditions = initialize_hashes options.dup
@defaults = defaults.dup
@request_method = conditions.delete(:method)
configure_components(defaults, conditions)
add_default_requirements
initialize_keys
Expand Down Expand Up @@ -342,8 +343,12 @@ def write_recognition(generator = CodeGeneration::RecognitionGenerator.new)
else g.constant_result(key, value)
end
end

g.go

if @request_method
g.if("@request.method == :#{@request_method}") { |gp| gp.go }
else
g.go
end

generator
end
Expand Down Expand Up @@ -469,17 +474,19 @@ def write_generation
end

def recognize(request)
string_path = request.path
@request = request

string_path = @request.path
string_path.chomp! if string_path[0] == ?/
path = string_path.split '/'
path.shift

hash = recognize_path(path)
return recognition_failed(request) unless hash && hash['controller']
return recognition_failed(@request) unless hash && hash['controller']

controller = hash['controller']
hash['controller'] = controller.controller_path
request.path_parameters = hash
@request.path_parameters = hash
controller.new
end
alias :recognize! :recognize
Expand Down

0 comments on commit 7a8883e

Please sign in to comment.