Rails/Paperclip - 跳过图像处理 [英] Rails / Paperclip - skipping image processing
本文介绍了Rails/Paperclip - 跳过图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何跳过基于虚拟属性的后期处理?
How can I skip post processing based on a virtual attribute?
我的虚拟属性在 before_asset_post_process 回调中始终为零
My virtual attribute is always nil in the before_asset_post_process callback
创建
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
推荐答案
:asset
的赋值将在 :skip_thumb
的赋值之前发生,如果它在哈希中是第一个你传递给 Attachment.create()
.因此,如果您将代码更改为:
The assignment of :asset
will happen before the assignment of :skip_thumb
if it's first in the hash that you pass to Attachment.create()
. Therefore, it will work if you change your code to:
attachment = Attachment.create(skip_thumb: 1, asset: File.open(file.png))
我希望这不会太晚而有用...
I hope this is not too late to be useful...
这篇关于Rails/Paperclip - 跳过图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文