diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-26 20:07:34 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-26 20:07:34 +0000 |
commit | dcaa074abf5691a933b9c55159cc7d98a02b3b2f (patch) | |
tree | 4d58fee286eaa957e141939dcbd898055cab2325 /actionpack/lib/action_controller/routing.rb | |
parent | 42ebf559cc6ed80fa3bf55ecc1dea7c9e593f45e (diff) | |
download | rails-dcaa074abf5691a933b9c55159cc7d98a02b3b2f.tar.gz rails-dcaa074abf5691a933b9c55159cc7d98a02b3b2f.tar.bz2 rails-dcaa074abf5691a933b9c55159cc7d98a02b3b2f.zip |
Routing: respond with 405 Method Not Allowed status when the route path matches but the HTTP method does not. Closes #6953.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6862 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/routing.rb')
-rw-r--r-- | actionpack/lib/action_controller/routing.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 00d5050b7e..4a1eda82bf 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -251,6 +251,8 @@ module ActionController # TODO: , (comma) should be an allowed path character. SEPARATORS = %w( / ; . , ? ) + HTTP_METHODS = [:get, :head, :post, :put, :delete] + # The root paths which may contain controller files mattr_accessor :controller_paths self.controller_paths = [] @@ -1345,7 +1347,16 @@ module ActionController routes.each do |route| result = route.recognize(path, environment) and return result end - raise RoutingError, "no route found to match #{path.inspect} with #{environment.inspect}" + + allows = HTTP_METHODS.select { |verb| routes.find { |r| r.recognize(path, :method => verb) } } + + if environment[:method] && !HTTP_METHODS.include?(environment[:method]) + raise NotImplemented.new(*allows) + elsif !allows.empty? + raise MethodNotAllowed.new(*allows) + else + raise RoutingError, "No route matches #{path.inspect} with #{environment.inspect}" + end end def routes_by_controller |