使用Carrierwave获取图像尺寸:未定义的方法`[]'为零:NilClass

时间:2014-06-24 02:44:10

标签: ruby-on-rails ruby-on-rails-4 carrierwave rmagick

我正在尝试根据上传的图片尺寸制作不同版本的图片,我不明白为什么我的代码没有保存宽度和高度值。我正在使用Carrierwave。这是我的代码:

class HeadUploader < CarrierWave::Uploader::Base

  include CarrierWave::RMagick

  #Create different versions of your uploaded files:
  version :thumb do
    process :image_dimensions
    width = @geometry.width
    height = @geometry.height


    if width < height
      process :resize_to_limit => [30, 60]
    else
      process :resize_to_limit => [60, 30]
    end
  end

  def image_dimensions
    manipulate! do |img|
      @geometry = { width: img.columns, height: img.rows }
    end
  end

end

对于第width = @geometry.width行,我收到以下错误:undefined method 'width' for nil:NilClass

您认为什么可能是个问题?

0 个答案:

没有答案