2015-07-01 18 views
2

2.2和raisl 4.1。我試圖從用戶那裏讀取一個xlsx文件。Encoding :: UndefinedConversionError -ASCII-8BIT到UTF-8軌道上的紅寶石

<%= form_for(@attachment, :html => { :multipart => true,:class => 'form-horizontal' }) do |f| %> 
    <div class="form-group"> 
    <label for="inputEmail3" class="col-sm-2 control-label">List of Company Name</label> 
    <div class="col-sm-10"> 
     <%= f.file_field :attachment,class: 'form-control' %> 
    </div> 
    </div> 
    <div class="form-group"> 
    <div class="col-sm-offset-2 col-sm-10"> 
     <%= f.submit 'Import Company Name list',:class => "btn btn-primary" %> 
    </div> 
    </div> 
<% end %> 

在控制檯

Parameters: {"utf8"=>"✓", "authenticity_token"=>"BJMhP6MnjUH17esTRxtaViIpBXL/aMzQgzuOI0a9LjI=", "attachment"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x00000006cd25e8 @tempfile=#<Tempfile:/tmp/RackMultipart20150701-9558-59shsp>, @original_filename="Book2.xlsx", @content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", @headers="Content-Disposition: form-data; name=\"attachment[attachment]\"; filename=\"Book2.xlsx\"\r\nContent-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n">}, "commit"=>"Import Company Name list"} 

即使使用UTF-8馬克傳遞參數我得到

Encoding::UndefinedConversionError - "\xA0" from ASCII-8BIT to UTF-8: 

誤差..試過多樣溶液等.force_encoding('UTF -8') mime :: type但沒有解決?

有沒有人有關於這個問題的想法?

回答

1

我發現爲什麼這發生的原因,我有我的Gemfile以下

gem 'meta_request','0.2.1' 

和消除這種寶石進行文件上傳的作品完美。

希望這會幫助別人...