javascript - File Upload Nil Photo Params Issue -



javascript - File Upload Nil Photo Params Issue -

i have rails 4 app i'm using jquery file upload send requests carrierwave. code looks like:

<input name='photo[image]' type='file' data-url='photos/create' multiple="true" class='fileupload'/>

and jquery:

$('.fileupload').fileupload({ datatype: 'json', done: function (e, data) { $.each(data.result.files, function (index, file) { alert(file.name); }); } });

and create action in photos controller:

def create @photo = photo.new(photo_params) respond_to |format| if @photo.save format.json { render json: @photo } else format.json { render json: @photo.errors, status: :unprocessable_entity } end end end private def photo_params params.require(:photo).permit! end

and photo model:

class photo < activerecord::base mount_uploader :image, imageuploader end

when create photo, carrierwave correctly creating image (in public/uploads directory), yet reason jquery comes error:

uncaught typeerror: cannot read property 'length' of undefined

i'm not sure what's causing this?

i should've left comment don't have plenty reputation, apologies.

i think need utilize data.files rather data.result.files

like this

$('.fileupload').fileupload({ datatype: 'json', done: function (e, data) { $.each(data.files, function (index, file) { alert(file.name); }); } });

javascript jquery ruby-on-rails ruby file

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -