On 03/27/2012 08:01 PM, Matt Wagner wrote:
This was a moderately challenging bug to track down, and Imre
deserves heaps of credit for tracking it down. The problem is that rack-restful_submit was
not rewriting the request on the Edit page, because it was a PUT and restful_submit only
works with POSTs.
The fix here is a simple one -- we don't use restful_submit for this form, and
instead fall back to the more traditional pattern of submitting the form and checking the
button's value. This fixes the issue and avoids any larger changes late in the game.
Imre also reports success by removing "config.middleware.use
Rack::RestfulSubmit" in application.rb, and replacing it with
"config.middleware.swap Rack::MethodOverride, 'Rack::RestfulSubmit'". I
don't fully understand the impact of that change just yet, so I'm reluctant to
propose that in a bugfix phase, but it deserves a look longer-term.
-- Matt
One note on Rack::RestfulSubmit:
As the documentation of Rack::RestfulSubmit states we should swap
Rack::RestfulSubmit with Rack::MethodOverride but instead of swapping we
just include it on the top of the default rack middleware stack.
The source of conflict between the two is the value of
env["REQUEST_METHOD"] which is first overwritten by Rack::MethodOverride
since it's lower in the stack. Rack::RestfulSubmit only overwrite the
request attributes if the request is a POST request.
Thus the restful_submit_tag is not working on any edit page in Conductor
because Rack::MethodOverride rewrites the request to a PUT request and
Rack::RestfulSubmit passes it to the next middleware without any
modification since it's not a POST one.
Another approach would be to fix rack-restful_submit to rely on the
value of env["rack.methodoverride.original_method"] instead of
env["REQUEST_METHOD"], but I haven't tested it so I am not sure if I
haven't missed anything.
Imre