Skip to content

Instantly share code, notes, and snippets.

@jamiehodge
Last active December 10, 2015 14:28
Show Gist options
  • Save jamiehodge/4447540 to your computer and use it in GitHub Desktop.
Save jamiehodge/4447540 to your computer and use it in GitHub Desktop.
Webmachine method override
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