为什么ImageMagick无法打开Paperclip上传文件?
我需要能够对它进行一些检查。
class Photo < ActiveRecord::Base
ATTACHMENT_STYLES = lambda do |attachment|
if is_something?(attachment.instance)
...
else
...
end
end
ATTACHMENT_PROCESSORS = lambda { |attachment| is_something?(attachment.instance) ? [:other_processor] : [:thumbnail] }
...
def self.is_something?(attachment)
file = Magick::ImageList.new(attachment)
...
end
end
但为什么我会这样做?
Magick::ImageMagickError in TopicsController#create
no decode delegate for this image format `0x00000004e3cc50>' @ error/constitute.c/ReadImage/544
Extracted source (around line #20):
file = Magick::ImageList.new(attachment)
app/models/photo.rb:20:in `new'
app/models/photo.rb:20:in `is_something?'
app/models/photo.rb:3:in `block in <class:Photo>'
答案 0 :(得分:1)
看起来你在if块中分配了一个值:
true if file.attachment_content_type = /gif/ && file.size
如果您尝试将其与正则表达式匹配,您实际上想要使用=~
,如下所示:
true if file.attachment_content_type =~ /gif/ && file.size