ajax fileupload through rails remotipart gem -
i have been trying upload images through remotipart , carrierwave. fileupload working fine, have installed remotipart gem enables file upload through ajax.now issue how send file through ajax(i mean jquery part).
this how i'm trying send file controller,but not working
$("#upload").live("submit",function(e) { e.preventdefault(); var study ={}; report.file =$("#new_upload").find('#upload_name').val(); $.ajax(this.action, { data: report, iframe: true, processdata: false }).complete(function(data) { console.log(data); }); }); here's form code:
<%= form_for(@upload,:url => { :action => "save_remotipart" },:html => {:multipart => true },:remote => (params[:action] == true )) |f| %> <fieldset> <legend class='required'> required fields </legend> <div class="field"> <%= f.label :name %><br /> <%= f.file_field :name %> </div> </fieldset> <div class="actions"> <%= f.submit %> </div> <% end %> when form submitted no parameters sent server. on abort i'm getting this:
{"object object"=>nil} please help me.
you don't have $("#upload").live(){}, adding :remote => true form ajax submit file-uploads done properly.
i using in 1 of projects (see form code below)
<%= simple_form_for @post, :remote => true, :multipart => true |f| %> <%= f.input :content, :label => false, :input_html => { :rows => '2', :id => "ibtb" } %> <%= f.input :file, :label => false %> <%= f.button :submit, "post" %> <% end %> i using simple_form gem, should work normal form since both these generate html @ end. illustration in github page gem doesn't utilize simple_form.
hope helps.
ruby-on-rails ruby-on-rails-3 carrierwave remotipart
No comments:
Post a Comment