Created
October 16, 2019 08:28
-
-
Save namiwang/11359a5e6217dbe24c587ecd6a98620f to your computer and use it in GitHub Desktop.
rack middleware to simulate PATCH by _name=POST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PatchSimulatingMiddleware | |
def initialize app | |
@app = app | |
end | |
def call env | |
request = Rack::Request.new(env) | |
if request.post? && ( request.params['_name'] == 'patch' ) | |
request.set_header 'REQUEST_METHOD', 'PATCH' | |
end | |
@app.call env | |
end | |
end | |
#application.rb | |
config.middleware.use PatchSimulatingMiddleware |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment