Created
August 27, 2010 18:34
-
-
Save shouichi/553918 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# This rack app overrides http method by __method=xxx query. | |
# | |
# Example | |
# | |
# link_to 'Destroy', post_path(@post, :__method => :delete) | |
class RequestMethodOverrider | |
HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS) | |
HTTP_METHOD_OVERRIDE_KEY = "__method".freeze | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
method = Rack::Utils.parse_query(env["QUERY_STRING"])[HTTP_METHOD_OVERRIDE_KEY].try(:upcase) | |
env["REQUEST_METHOD"] = method if HTTP_METHODS.include?(method) | |
@app.call(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment