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/base.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/base.rb')
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index dc5a1d18cd..8bff41d38d 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -22,6 +22,24 @@ module ActionController #:nodoc: @failures = failures end end + class MethodNotAllowed < ActionControllerError #:nodoc: + attr_reader :allowed_methods + + def initialize(*allowed_methods) + super("Only #{allowed_methods.to_sentence} requests are allowed.") + @allowed_methods = allowed_methods + end + + def allowed_methods_header + allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', ' + end + + def handle_response!(response) + response.headers['Allow'] ||= allowed_methods_header + end + end + class NotImplemented < MethodNotAllowed #:nodoc: + end class UnknownController < ActionControllerError #:nodoc: end class UnknownAction < ActionControllerError #:nodoc: |