无法使用Paperclip 4.0 Rails 3上传图像

我安装了ImageMagick,并安装了Gem Paperclip(4.0版)。 我已经添加:

Paperclip.options[:command_path] = 'C:\Program Files\ImageMagick-6.8.8-Q16' 

发展

我的photo.rb模型有这样的:

 has_attached_file :image validates_attachment_content_type :image, :content_type => ['image/jpeg', 'image/png', 'image/jpg'] 

我可以在photos / new.html.erb中select一个文件,但是一旦我点击“创build照片”button,页面会重新加载一个Paperclip特定的错误消息,并说:

 1 error prohibited this photo from being saved: Image translation missing: en.activerecord.errors.models.photo.attributes.image.spoofed_media_type 

有人可以帮忙吗? 谢谢

该消息是通过对内容欺骗进行验证检查而提出的。

对于Paperclip v.4,这会产生一个错误https://github.com/thoughtbot/paperclip/issues/1429

虽然Paperclip v.3,它似乎只是抛出一个弃用警告, https://github.com/thoughtbot/paperclip/issues/1423

所以我等待Paperclip团队在使用版本4之前解决这个bug。现在我宁愿继续使用版本3。

 gem "paperclip", "~> 3.5.3" 

将其添加到初始化程序以禁用欺骗保护:

 require 'paperclip/media_type_spoof_detector' module Paperclip class MediaTypeSpoofDetector def spoofed? false end end end 

这适用于Paperclip v3.5.1 (希望仍然可以在V4工作):

 has_attached_file :attachment, styles: lambda { |a| a.instance.is_image? ? { *** image_styles ***} : { *** video_styles ***}, processors: lambda { |a| a.is_video? ? [ :ffmpeg ] : [ :thumbnail ] } def is_video? attachment.instance.attachment_content_type =~ %r(video) end def is_image? attachment.instance.attachment_content_type =~ %r(image) end