gpt4 book ai didi

ruby-on-rails - Rails/Paperclip - 跳过图像处理

转载 作者:行者123 更新时间:2023-12-05 08:01:33 25 4
gpt4 key购买 nike

如何跳过基于虚拟属性的后期处理?

我的虚拟属性在 before_asset_post_process 回调中始终为 nil

创建

attachment = Attachment.create(asset: File.open(file.png), :skip_thumb => 1)

附加模型

class Attachment < AR::Base
attr_accessor :skip_thumb

has_attached_file :asset, :styles => lambda { |attachment| { :thumb => ["100>", 'jpg'] ,
:thumb_big => ["200>", 'jpg']
}
before_asset_post_process :proceed_or_cancel

def proceed_or_cancel
#self.skip_thumb is always nil
if (self.skip_thumb.present?)
return false
end
end

end

最佳答案

您是否在附件 模型中使用了attr_accessible?如果是这样,并且如果它不包含 skip_thumb,那么当您尝试通过批量分配来分配它时,这将失败(静默地)。

attr_accessible 的反义词是 attr_protected,如果你有 skip_thumb,请将其删除。

关于ruby-on-rails - Rails/Paperclip - 跳过图像处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13203171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com