我在使用ruby 2.1.8p440的Windows 10上使用Rails 4.2.5.1。我在RoR培训主页上做了一个简单的博客示例。我想在我的博文中添加图片。我使用了最新的paperclip(paperclip 5.0.0)。当我尝试上传文件时,它给了我这个错误:
`Command :: SET PATH=C:\Program Files\ImageMagick-7.0.2-Q16; C:\Program Files (x86)\GnuWin32\bin;%PATH% & file -b --mime "C:/Users/tgumus/AppData/Local/Temp/561dc621f913ff416b348cf2a6c410a620160703-5964-tl8mjj.jpg"
[paperclip] Content Type Spoof: Filename 876f0725-508d-430c-a638-abfeb8e7914e.jpg (image/jpeg from Headers, ["image/jpeg"] from Extension), content type discovered from file command: . See documentation to allow this combination.
(0.0ms) begin transaction
Command :: SET PATH=C:\Program Files\ImageMagick-7.0.2-Q16; C:\Program Files (x86)\GnuWin32\bin;C:\Program Files\ImageMagick-7.0.2-Q16; C:\Program Files (x86)\GnuWin32\bin;%PATH% & file -b --mime "C:/Users/tgumus/AppData/Local/Temp/561dc621f913ff416b348cf2a6c410a620160703-5964-180jfb2.jpg"
[paperclip] Content Type Spoof: Filename 876f0725-508d-430c-a638-abfeb8e7914e.jpg (image/jpeg from Headers, ["image/jpeg"] from Extension), content type discovered from file command: . See documentation to allow this combination.
(0.0ms) rollback transaction
Redirected to http://localhost:3000/articles
Completed 302 Found in 146ms (ActiveRecord: 0.0ms)`
我将环境变量添加到development.rb并测试它们。他们似乎独自工作。我刚刚复制了文档的代码。我找不到解决方案。我删除并再次安装了imagemagick和file.exe。我安装了Imagemagick的静态版本。
我的 development.rb 文件如下所示
Rails.application.configure do
Paperclip.options[:command_path] = 'C:\Program Files\ImageMagick-7.0.2-Q16; C:\Program Files (x86)\GnuWin32\bin'
我的modal.rb( article.rb )文件如下所示:
has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/assets/images/:style/missing.png"
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
正如您所看到的,它不会上传任何文件,也不会创建文章并返回我的主页。 你能帮忙吗?我错过了什么?
谢谢