本文介绍了无法使用Paperclip 4.0 Rails 3上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了ImageMagick,并且已经安装了宝石Paperclip(4.0版).我添加了:

I've installed ImageMagick and I've installed the gem Paperclip (version 4.0). I've added:

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

到development.rb

to the development.rb

我的photo.rb模型具有以下内容:

My photo.rb Model has this:

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

我可以在photos/new.html.erb中选择一个文件,但是一旦单击创建照片"按钮,页面就会重新加载,并显示Paperclip特定错误消息:

I can choose a file in photos/new.html.erb but once I click on 'Create photo' button, the page reloads with a Paperclip specific error message saying:

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

有人可以帮忙吗?谢谢

Can someone help please?Thanks

推荐答案

该消息是通过对内容欺骗的验证检查引发的.

That message is raised by a validation check for content spoofing.

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

For Paperclip v.4 this generates a bug https://github.com/thoughtbot/paperclip/issues/1429

在进行Paperclip v.3时,似乎只是抛出了弃用警告, https://github.com/thoughtbot/paperclip/issues/1423

While for Paperclip v.3, it seems it just throws a deprecation warning, https://github.com/thoughtbot/paperclip/issues/1423

因此,在使用版本4之前,我将等待Paperclip团队解决此错误.目前,我宁愿继续使用版本3.

So I'd wait for Paperclip team to solve this bug before using version 4. At the moment I'd rather keep using version 3.

gem "paperclip", "~> 3.5.3"

这篇关于无法使用Paperclip 4.0 Rails 3上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 15:02