jeudi 3 septembre 2015

rails-jquery-uploader does not send post params

im using the jQuery-File-Upload from blueimp to upload files.

i've looked around to some same issues here like this but its not really the same error.

i added the gem to my assets group in the gemfile and bundle it

gem "jquery-fileupload-rails"

the import controller

class Admin::ImportsController < ApplicationController
  def new
    @import = Import.new
  end

  def create
    filename = params[:import][:filename]
    File.open(Rails.root.join('tmp', filename.original_filename), 'wb') do |file|
      file.write(filename.read)
    end
  end
end

my haml form

= form_for [:admin, @import] do |form|
  = form.file_field :filename
  = form.submit :go

binding the fileupload()

jQuery ->
  $('#new_import').fileupload
    dataType: "script"

and my import class

class Import
  extend ActiveModel::Naming
  include ActiveModel::Conversion
  include ActiveModel::Validations
  attr_accessor :filename

  def persisted?
    false
  end
end

application.js

//= require jquery-fileupload/basic

without the jquery-fileupload the upload works fine. but with activating the fileupload, i can choose a file, and then it will perform the post to the server but without params.

the postdata looks like:

[object FormData]&authenticity_token=1NRXgkIwB4OqIoDoWHnWR4KT%2B0SQAf%2FgqLEHix476SI%3D

it seems he didn't find the form elements correctly. but why?

Aucun commentaire:

Enregistrer un commentaire