Carrierwave条件版抛出参数错误

时间:2013-06-24 13:12:05

标签: ruby-on-rails ruby-on-rails-3.2 carrierwave

我遵循官方的github存储库示例,但是当我在版本方法上定义条件时,我总是得到:

ArgumentError - wrong number of arguments (1 for 0):
(gem) carrierwave-0.8.0/lib/carrierwave/uploader/versions.rb:198:in `block in active_versions'
(gem) carrierwave-0.8.0/lib/carrierwave/uploader/versions.rb:192:in `active_versions'

这是我的代码:

class PhotoUploader < CarrierWave::Uploader::Base

    include CarrierWave::MiniMagick
    storage :file

    version :thumb_75, :if => :is_user? do
        process :resize_to_fill => [75, 75]
    end

    version :thumb_87, :if => :is_question? do
        process :resize_to_fill => [87, 87]
    end

    protected
    def is_user?
        model.class.to_s == 'Photo'
    end

    protected
    def is_question?
        model.class.to_s == 'Question'
    end

end

如果我删除它的工作条件...... 关于它可能是什么的任何想法? 感谢

1 个答案:

答案 0 :(得分:6)

您必须使is_user?is_question?方法接受参数:

protected
def is_user?(picture)
    model.class.to_s == 'Photo'
end

protected
def is_question?(picture)
    model.class.to_s == 'Question'
end