我安装了ImageMagick并且我安装了宝石Paperclip(版本4.0)。我添加了:
Paperclip.options[:command_path] = 'C:\Program Files\ImageMagick-6.8.8-Q16'
到development.rb
我的照片.rb模型有这个:
has_attached_file :image
validates_attachment_content_type :image, :content_type => ['image/jpeg', 'image/png', 'image/jpg']
我可以在photos / new.html.erb中选择一个文件,但是一旦我点击“创建照片”按钮,页面就会重新加载Paperclip特定的错误消息:
1 error prohibited this photo from being saved:
Image translation missing:
en.activerecord.errors.models.photo.attributes.image.spoofed_media_type
有人可以帮忙吗? 感谢
答案 0 :(得分:10)
将此添加到初始化程序以禁用欺骗保护:
require 'paperclip/media_type_spoof_detector'
module Paperclip
class MediaTypeSpoofDetector
def spoofed?
false
end
end
end
答案 1 :(得分:4)
通过内容欺骗的验证检查引发该消息。
对于Paperclip v.4,这会产生错误https://github.com/thoughtbot/paperclip/issues/1429
对于Paperclip v.3,它似乎只是抛出了弃用警告,https://github.com/thoughtbot/paperclip/issues/1423
所以我等到Paperclip团队在使用版本4之前解决了这个错误。目前我还是继续使用版本3.
gem "paperclip", "~> 3.5.3"
答案 2 :(得分:0)
这适用于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