Last active
December 10, 2015 14:28
-
-
Save jamiehodge/4447540 to your computer and use it in GitHub Desktop.
Webmachine method override
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
require "webmachine" | |
class MethodOverride < Webmachine::Resource | |
def allowed_methods | |
override_method! | |
%w(GET PUT DELETE) | |
end | |
private | |
def override_method! | |
if request.post? && ["multipart/form-data", "application/x-www-form-urlencoded"].include?(request.headers['content-type']) && params["_method"] | |
request.instance_variable_set(:@method, params["_method"].upcase) | |
end | |
end | |
def params | |
@params ||= Hash[URI.decode_www_form(request.body.to_s)] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment