vendor/assets/javascripts/jquery.remotipart.js in remotipart-1.2.0 vs vendor/assets/javascripts/jquery.remotipart.js in remotipart-1.2.1
- old
+ new
@@ -7,11 +7,14 @@
$.remotipart = remotipart = {
setup: function(form) {
// Preserve form.data('ujs:submit-button') before it gets nulled by $.ajax.handleRemote
- var button = form.data('ujs:submit-button');
+ var button = form.data('ujs:submit-button'),
+ csrfParam = $('meta[name="csrf-param"]').attr('content'),
+ csrfToken = $('meta[name="csrf-token"]').attr('content'),
+ csrfInput = form.find('input[name="' + csrfParam + '"]').length;
form
// Allow setup part of $.rails.handleRemote to setup remote settings before canceling default remote handler
// This is required in order to change the remote settings using the form details
.one('ajax:beforeSend.remotipart', function(e, xhr, settings){
@@ -39,9 +42,12 @@
settings.processData = false;
// Modify some settings to integrate JS request with rails helpers and middleware
if (settings.dataType === undefined) { settings.dataType = 'script *'; }
settings.data.push({name: 'remotipart_submitted', value: true});
+ if (csrfToken && csrfParam && !csrfInput) {
+ settings.data.push({name: csrfParam, value: csrfToken});
+ }
// Allow remotipartSubmit to be cancelled if needed
if ($.rails.fire(form, 'ajax:remotipartSubmit', [xhr, settings])) {
// Second verse, same as the first
$.rails.ajax(settings);