简体   繁体   中英

Dropzonejs rails doesn't render js.erb file

Hi i need to upload images with dropzone js to my website. i am using
dropzonejs rails gem it uploads correctly but after upload it doesn't render js.erb file

my js.coffee

Dropzone.options.photoDropzone =
  paramName: "paper[paper]"
  maxFilesize: 10
  addRemoveLinks: true
  init: ->
    @on "removedfile", (file) ->
      if file.xhr
        $.ajax
          url: "" + ($("#photo-dropzone").attr("action")) + "/" + (JSON.parse(file.xhr.response).id)
          type: "DELETE"

my form

  = form_for @paper, url: multiple_upload_papers_path(format: :js), remote: true, multipart: true, method: :post,  html: {class: :dropzone, id: 'photo-dropzone'} do |p|
    = p.hidden_field :id

my controller action

def multiple_upload
    @paper = Paper.new
    @paper.paper = params[:paper][:paper]
    @paper.save
    respond_to do |format|
        format.js
    end
end

and my js.erb file has

console.log('Successfull');

line. It is working correctly it uploads all images but it doesn't render js.erb file after upload. When i check from chrome console it returns js but it doesn't runs it.

chrome控制台结果

just add this to your Dropzone options

   success: function (response) {
                eval(response.xhr.response);
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM