Remotipart is changing the action from PUT to GET

119 Views Asked by At

I have a story model that serves as a wrapper for many posts. Posts may have photo attachments, and I use remotipart and paperclip to handle the image uploading and processing.

This works perfectly fine when a user POSTS a new post. I want to allow post authors to edit their posts/uploaded images; and this is where the problem occurs.

When a user clicks an edit button I alter the form that I originally used when users create posts so that that same form can be used to edit the post. As part of that I change I modify the <form> tag from:

<form id="new_post_for_story_241" class="new_post" accept_charset="UTF-8" action="/stories/241/posts.json" data-remote="true" enctype="multipart/form-data" method="post" novalidate="novalidate" target="">

to

<form id="new_post_for_story_241" class="new_post" accept_charset="UTF-8" action="/stories/241/posts/287.json" data-remote="true" enctype="multipart/form-data" method="put" novalidate="novalidate" target="">

Again, this works fine to PUT edits if the user doesn't include an image. It breaks, however, if the form contains a new image. For whatever reason, if the user wants to upload a new image as part of the altered form, the form is submitted with a GET action. Triggering this:

Started GET "/stories/241/posts/287.json?post%5Bphoto%5D=champcourse15thgreen.jpg&post%5Bcontents%5D=another+pic%0D%0A&remotipart_submitted=true&X-Requested-With=IFrame&X-Http-Accept=text%2Fjavascript%2C+application%2Fjavascript%2C+application%2Fecmascript%2C+application%2Fx-ecmascript%2C+*%2F*%3B+q%3D0.01" for 127.0.0.1 at 2013-05-22 10:54:50 -0700

ActionController::RoutingError (No route matches [GET] "/stories/241/posts/287.json"):

Anyone know why this is happening, and more importantly, have a fix for it?

1

There are 1 best solutions below

0
On

You likely have an old version of the remotipart dependency jquery-iframe-transport which has incorrect code for setting the form's method (it is hardcoded instead of copying the original form's method). It's been fixed since.