-1

我将我的应用程序从 ruby​​ 1.9.3 升级到 ruby​​ 2.0,让我的大部分 gem 没有升级。一切正常,但是当我尝试上传图片时,出现此错误:

NoMethodError - undefined method `[]=' for nil:NilClass:
  app/uploaders/image_uploader.rb:91:in `block in optimize'
  /home/stefpe/.rvm/gems/ruby-2.0.0-p195@Lefkada/bundler/gems/carrierwave-5ee108128b40/lib/carrierwave/processing/rmagick.rb:263:in `manipulate!'
  app/uploaders/image_uploader.rb:90:in `optimize'
  /home/stefpe/.rvm/gems/ruby-2.0.0-p195@Lefkada/bundler/gems/carrierwave-5ee108128b40/lib/carrierwave/uploader/processing.rb:85:in `block in process!'
  /home/stefpe/.rvm/gems/ruby-2.0.0-p195@Lefkada/bundler/gems/carrierwave-5ee108128b40/lib/carrierwave/uploader/processing.rb:81:in `each'
  /home/stefpe/.rvm/gems/ruby-2.0.0-p195@Lefkada/bundler/gems/carrierwave-5ee108128b40/lib/carrierwave/uploader/processing.rb:81:in `process!'
  /home/stefpe/.rvm/gems/ruby-2.0.0-p195@Lefkada/bundler/gems/carrierwave-5ee108128b40/lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks'
  /home/stefpe/.rvm/gems/ruby-2.0.0-p195@Lefkada/bundler/gems/carrierwave-5ee108128b40/lib/carrierwave/uploader/callbacks.rb:18:in `each'
  /home/stefpe/.rvm/gems/ruby-2.0.0-p195@Lefkada/bundler/gems/carrierwave-5ee108128b40/lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks'

image_uploader.rb 基于 /carrierwave/processing/rmagick.rb 示例 manipulate函数:

  def optimize
    manipulate! do |img, index, options|
      options[:write] = {
    :quality => 50,
    :depth => 8,
    :interlace => "Magick::PlaneInterlace"
      }
      img.strip!
    end
  end

配置:服务器:heroku,本地开发:linux

红宝石 1.9.3 -> 2.0

导轨 3.2.13

载波 0.6.2

rmagick 2.13.1

雾 1.3.1

知道为什么与 ruby​​-2.0.0 不兼容吗?

先感谢您!

4

3 回答 3

0

对我有用的是在操作结束时返回图像!在你的情况下:

def optimize
  manipulate! do |img, index, options|
    options[:write] = {
      :quality => 50,
      :depth => 8,
      :interlace => "Magick::PlaneInterlace"
    }
    img.strip!
    img
  end
end
于 2014-01-10T06:04:58.050 回答
0

我做了: sudo apt-get install libmagickwand-dev

然后 gem 安装 rmagick

有效。请参阅: rmagick gem install "找不到 Magick-config"

于 2013-08-29T14:10:26.067 回答
0

您应该尝试更新一些 gem——carrierwave 在 2012 年 4 月可能还没有与 ruby​​ 2 完全兼容。

进一步的激励:Carrierwave甚至没有将选项传递到传递给的块中,manipulate!直到0.7

于 2013-08-29T14:38:00.977 回答