remotipart
remotipart copied to clipboard
Remotipart form send with post method
Hi,
I have some problems with remotipart, when I submit this form :
true, :html => { :multipart => true }) do |f| %>
When I click on my avatar (image_tag), the file field pop and once a file is selected, jquery submit the form.
But the form is sent with the POST method, not the PUT/PATCH (if I remove remote => true and submit the form manually, the method is the right one : PUT).
This is a remotipart issue ?
Using rails (4.0.0) Using jquery-ui-rails (4.1.1) Using remotipart (1.2.1)
Try adding :method => :put
to your form_for
. So, your above snippet should look like this:
<%= form_for(@user, :remote => true, :html => { :multipart => true, :method => :put }) do |f| %>
<%= f.file_field :avatar, style: 'display:none' %>
<% end %>
Thanks for the reply, i've already tested this tip, but it didn't work : the form is sent with POST method.
I don't understand : when I don't use "remote => true" it's a PUT method, if I add it, it's a POST method :/
the problem is here:
https://github.com/JangoSteve/remotipart/blob/master/vendor/assets/javascripts/jquery.iframe-transport.js#L130
you need to copy method
attribute from original form, but don't forget fallback to post
Sorry but i don't understand what do you mean by copy method and fallback to post, can you explain me this more precisely please ?
Thank you for the reply, I understand where is the problem but I don't see clearly how to solve it :)
@Badoche I think @attenzione proposed you to make some changes in source code to teach iframe transport to use custom method
attribute base on original form data but by default use POST
.
this is better version of jquery.iframe-transport
https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.iframe-transport.js
@attenzione have you already got a working remotipart integration? I need the same unobtrusive behavior, but the original jquery.iframe-transport
have different interface than that one from jQuery-File-Upload
, so it can't be a drop-in replacement.
i'm not, because don't need it, but solution should be easy, you need replace
form = $("<form enctype='multipart/form-data' method='post'></form>");
with something like this
options.type = (options.type || options.method).toLowerCase() || 'post';
form = $("<form enctype='multipart/form-data' method='" + options.type + "'></form>");
@attenzione yes, I understand it. But I asked about using this version: https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.iframe-transport.js
@killthekitten ou, can't help with it, sorry. In another project i'm just using bluimp file uploader, not remotipart
@killthekitten, also you can check my update to this file, to be able to restore form file element on fail https://github.com/attenzione/remotipart/commit/73a4f7d752c17952ae4eb7b9cbc44d295ced2c38
@attenzione seems that my problem was in something else, post/put/patch stuff works without any changes now. Re-checking.