1
  def upload
    uploaded_io = params[:post][:image]
    File.open(Rails.root.join('app/assets', 'uploads', uploaded_io.original_filename), 'w') do |file|
      file.write(uploaded_io.read)
      params[:post][:image] = uploaded_io.original_filename
    end
  end

这在我在 OS X 上的开发机器上运行良好,但是当运行相同的代码 eon heroku 时,我收到 500 错误,当我检查日志时,这似乎是导致它的原因

2012-09-21T16:57:08+00:00 app[web.1]: Encoding::UndefinedConversionError ("\xB6" from ASCII-8BIT to UTF-8):
2012-09-21T16:57:08+00:00 app[web.1]:   app/controllers/posts_controller.rb:86:in `write'
2012-09-21T16:57:08+00:00 app[web.1]:   app/controllers/posts_controller.rb:86:in `block in upload'
2012-09-21T16:57:08+00:00 app[web.1]:   app/controllers/posts_controller.rb:85:in `open'
2012-09-21T16:57:08+00:00 app[web.1]:   app/controllers/posts_controller.rb:85:in `upload'
2012-09-21T16:57:08+00:00 app[web.1]:   app/controllers/posts_controller.rb:61:in `update'

我不知道该怎么做

4

1 回答 1

0

我知道这已经很长时间了,但也许这可以帮助别人:

您可以尝试 File.open(Rails.root.join('app/assets', 'uploads', upload_io.original_filename), 'wb') (使用 wb 而不仅仅是 w)。

于 2014-02-15T18:11:20.700 回答