view
<div class="top-main-section-area">
<div id="upload-area" class="uploader1" onclick="$('#post_image').click()">
<div class="message" id="slider-message">
<center>
<font color="#808080">click here to upload sliderimages</font>
</center>
</div>
<%= f.file_field :images , array: true , type:'file' ,:onchange => 'readURL(this)',class:'slide-img',multiple: true, id:'files' %>
<img id="slide_image" src="#" alt="image" style="display: none;" class="slide_image" />
</div>
</div>
js file
window.onload = function() {
var array = [];
document.getElementById('files').addEventListener('change', handleFileSelect, false);
function handleFileSelect(evt) {
var count = 0;
console.log("hariii");
var files = evt.target.files;
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
count++;
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = [
'<img style="height: 75px; border: 1px solid #000; margin: 5px" src="',
e.target.result,
'" title="', escape(theFile.name),
'"/>'
].join('');
array.push(theFile.name);
document.getElementById('thumbnail').insertBefore(span, null);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
//console.log(array);
}
//console.log(count);
//console.log(array);
return array;
}
$(function() {
$('#slider-submit').on('click', function() {
//console.log(array)
console.log(JSON.stringify(array));
$.ajax({
type: "POST",
url: "/usr_vendor_website/slidecreate",
dataType: "json",
data: {
A: JSON.stringify(array)
},
processData: false,
contentType: 'application/json;',
success: function(result) {
console.log('ok');
//alert("Item scuessfully added to the Cart");
}
})
});
})
}
rails method access line
@usr_vendor_web_slide.images = params[:A]
I try to store rails uploaded images in javascript array and pass this array to rails controller. ajax part gives success result in console log but in rails controller got nil object. I cannot identify what is the issue of this. My target is carrierwave upload images store in jquery array and pass it in to postgresql array column using rails controller.appreciate your ideas and helps.