使用rails的Ajax文件上传在IE9上不起作用

时间:2013-11-19 14:52:57

标签: ruby-on-rails jquery-file-upload jquery-fileupload-rails

我正在尝试使用jquery-fileupload和rails 4上传文件。它适用于Firefox / Chrome但不适用于IE。

application.js.coffee:

#= require jquery
#= require jquery_ujs
#= require jquery-fileupload/basic
...

view.rb:

= form_for person,
    url: update_avatar_path, method: :post, remote: true,
    authenticity_token: true, multipart: true do |f|
    - if person.avatar?
      = f.hidden_field :remove_avatar, value: '1'
      = f.submit "Remove", class: "btn btn-mini"
    - else
      .fileupload-buttonbar
        .progress.fileupload-progressbar{:hidden => ""}
          .bar{:style => "width: 0%;"}
        %span.btn.btn-mini.fileinput-button
          %i.icon-plus
          %span
            = t('add_picture')
            \...
          = f.file_field :avatar, id: 'fileupload'

update_avatar.js:

$('#fileupload').fileupload
  replaceFileInput: false
  formData: $('#fileupload').closest('form').serializeArray()
  add: (e, data) ->
    $('.progress').show()
    data.submit()
  done: (e, data) ->

  progress: (e, data) ->
    progress = parseInt(data.loaded / data.total * 100, 10)
    $('.progress .bar').css('width', progress + '%')

controller.rb:

def update_avatar
  avatar = avatar_params
  if (!@person.update_attributes(avatar))
    flash.now[:error] = @person.errors.full_messages.join(', ')
  else
    # Success if we updated the avatar or removed it.
    remove = avatar[:remove_avatar]
    if remove.blank? || remove == '1'
      flash.now[:success] = 'Successfully updated.'
    end
  end
end

这是IE发送的内容:

Started POST "/people/1853/update_avatar" for 192.168.64.1 at 2013-11-19 09:40:48 -0500
Processing by PeopleController#update_avatar as HTML
  Parameters: {"utf8"=>"✓",     "authenticity_token"=>"4pcx0jCiXmircEl6KgZFtuIPis440uMMnlJoE++NqQk=", "person"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x007f20c0900578 @tempfile=#<Tempfile:/tmp/RackMultipart20131119-15247-lyxibq>, @original_filename="Koala.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"person[avatar]\"; filename=\"C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "id"=>"1853"}

“AS HTML”在FF / Chrome中不会发生,我认为这可能与此问题有关。我已经按照指定添加了iframe中间件,但它没有什么区别。

这是回复:

Completed 500 Internal Server Error in 1180ms

ActionView::MissingTemplate (Missing template people/update_avatar,     application/update_avatar with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml]}. Searched in:
  * "/home/jkolb/Development/ago-git/resumedb/app/views"

0 个答案:

没有答案