 
   url = $bulkAction.attr('href')
   title = $bulkAction.text()
-  token = $bulkAction.parent('li').data('authenticity-token')
+  downloadToken = $bulkAction.parent('li').data('authenticity-token')
+  token = $table.data('authenticity-token')
   values = $.map($selected, (input) -> input.getAttribute('value'))
   method = $bulkAction.data('ajax-method')
 

    $.ajax(
      method: method,
      url: url,
      data: { ids: values }
    ).done((response) ->
      success = response['message'] || "Successfully completed #{title} bulk action"
      $table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(success, 'success') and restoreSelected($(e.target), values)


  $table.dataTable().data('bulk-actions-restore-selected-values', values)

  if downloadToken # This is a file download
    $.fileDownload(url,
      httpMethod: 'POST',
      data: { ids: values, authenticity_token: downloadToken }
      successCallback: ->
        success = "Successfully completed #{title} bulk action"
        $table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(success, 'success')
