A New Gem For People Who Can’t Use HTTP Methods Other Than POST

Itch:

I needed to be able to look at query params in the URL for the _method parameter Rails uses to fake different types of POST-like requests. Rails currently doesn’t do this for you as it uses Rack::MethodOverride, and that doesn’t look at GET parameters. It only looks at the X-Http-Method-Override header and POST form params. Some Rails users filed a ticket awhile ago about it, and it is an ongoing concern(see #2289).

Scratch:

Being a go getter, active, knows his way around a gemspec sort of person, I whipped up a library so if you run into this problem, you can fix it easily. Rack::MethodOverrideWithParams is the result. It is a drop-in replacement for Rack::MethodOverride, so all you have to do is replace Rack::MethodOverride in your stack with it and you’ll be rocking query param method overriding goodness.

“How easily”, you might ask.┬áLet me show you. It’s just a couple of code additions:
Gemfile
gem "rack-methodoverride-with-params", "~> 1"
config/environment.rb
config.middleware.swap Rack::MethodOverride, Rack::MethodOverrideWithParams

Done.

What do you think?

Links

github.com/baroquebobcat/rack-methodoverride-with-params

rubygems.org/gems/rack-methodoverride-with-params

Rails ticket #2289

Comments are closed.