I use carrier and dropzone. Everything seems fine, however, when I try to click the delete image button, even if it is deleted from the database, the image remains on the container.
Here's what it looks like:

When I click to remove a link to a file, they all become:

So, I clicked on all the buttons to delete files, they are deleted from the database, however they remain on the page. I think this is due to the js code (end part) below,
<script type="text/javascript">
$(document).ready(function(){
Dropzone.autoDiscover = false;
$("#picture-dropzone").dropzone({
maxFilesize: 5,
paramName: "picture[image]",
acceptedFiles: "image/*",
addRemoveLinks: true,
success: function(file, response){
$(file.previewTemplate).find('.dz-remove').attr('id', response.fileID);
$(file.previewTemplate).find('.dz-remove').attr('boat_id', response.boatID);
$(file.previewElement).addClass("dz-success");
},
removedfile: function(file){
var id = $(file.previewTemplate).find('.dz-remove').attr('id');
var boat_id = $(file.previewTemplate).find('.dz-remove').attr('boat_id');
$.ajax({
type: 'DELETE',
url: '/boats/' + boat_id + '/pictures/' + id,
success: function(file){
}
});
}
});
});
</script>
if someone wonders
class PicturesController < ApplicationController
before_action :logged_in_user
before_filter :load_parent
def new
@picture = @boat.pictures.new
@pictures = @boat.pictures.all
end
def show
@picture = @boat.pictures.find(params[:id])
end
def create
@picture = @boat.pictures.new(picture_params)
if @picture.save
render json: { message: "success", fileID: @picture.id, boatID: @boat.id }, :status => 200
else
render json: { error: @picture.errors.full_messages.join(',')}, :status => 400
end
end
def edit
@picture = Picture.find(params[:id])
end
def update
@picture = @boat.pictures.find(params[:id])
if @picture.update_attributes(picture_params)
flash[:notice] = "Successfully updated picture."
render 'index'
else
render 'edit'
end
end
def destroy
@picture = @boat.pictures.find(params[:id])
if @picture.destroy
render json: { message: "File deleted from server" }
flash[:notice] = "Successfully destroyed picture."
else
render json: { message: @picture.errors.full_messages.join(',') }
end
end
private
def picture_params
params.require(:picture).permit(:name, :image)
end
def load_parent
@boat = Boat.find(params[:boat_id])
end
end