Skip to content

Instantly share code, notes, and snippets.

@namiwang
Created October 16, 2019 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namiwang/11359a5e6217dbe24c587ecd6a98620f to your computer and use it in GitHub Desktop.
Save namiwang/11359a5e6217dbe24c587ecd6a98620f to your computer and use it in GitHub Desktop.
rack middleware to simulate PATCH by _name=POST
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