When a file is added and redirected correctly, no notice is displayed. However, if xhr is not used, the notice will appear.
application.js
var files = evt.target.files || evt.dataTransfer.files;
// files is a FileList of File objects. List some properties.
for (var i = 0, f; f = files[i]; i++) {
var xhr = new XMLHttpRequest();
xhr.open("POST", 'report_drag', false);
xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
xhr.setRequestHeader("X_FILENAME", "file." + f.name.split('.').pop());
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
xhr.send(f);
}
controller.rb
def report_drag
filename = "report/#{DateTime.now.year}-#{DateTime.now.month}/" + "#{Vendor.where(id: current_user.id).first.title}" + "#{File.extname("#{request.headers['HTTP_X_FILENAME']}")}"
File.open(File.join(filename), "wb") { |f| f.write(request.body.read) }
redirect_to report_url, notice: "File successfully added."
end