2014-12-03 45 views
0

为什么ImageMagick无法打开我的Paperclip上传?Paperclip和RMagick:此图片格式无解码代理

我需要能够运行一些检查。

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>' 

回答

1

它看起来像你的,如果块分配一个值:

true if file.attachment_content_type = /gif/ && file.size 

如果你想匹配它的正则表达式,你真的想使用=~这样的:

true if file.attachment_content_type =~ /gif/ && file.size 
+0

非常感谢您的意见!然而,不幸的是问题仍然存在。 – 2014-12-03 21:33:04