Class: HttpMethodNotAllowed
- Inherits:
-
Object
- Object
- HttpMethodNotAllowed
- Defined in:
- lib/http_method_not_allowed.rb
Overview
Render 405 response for ActionController::UnknownHttpMethod exceptions like: (ActionController::UnknownHttpMethod) “CONNECT, accepted HTTP methods are get, head, put, post, delete, and options” (ActionController::UnknownHttpMethod) “PROPFIND, accepted HTTP methods are get, head, put, post, delete, and options”
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ HttpMethodNotAllowed
constructor
A new instance of HttpMethodNotAllowed.
Constructor Details
#initialize(app) ⇒ HttpMethodNotAllowed
Returns a new instance of HttpMethodNotAllowed.
7 8 9 |
# File 'lib/http_method_not_allowed.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/http_method_not_allowed.rb', line 11 def call(env) if ActionDispatch::Request::HTTP_METHODS.include?(env['REQUEST_METHOD'].upcase) @status, @headers, @response = @app.call(env) [@status, @headers, @response] else Rails.logger.info("ActionController::UnknownHttpMethod: #{env['REQUEST_METHOD']}") [405, { 'Content-Type' => 'text/plain' }, ['Method Not Allowed']] end end |