Image Paperclip :: Errors :: NotIdentifiedByImageMagickError #Windows

我已经厌倦了这个错误……我尝试了互联网上的一切(我发现到目前为止)

gem

gem 'paperclip', '~> 4.3', '>= 4.3.6' 

配置/环境/ development.rb

 Paperclip.options[:command_path] = "/c/Program Files/ImageMagick-7.0.1-Q16/" Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin' 

ImageMagick / convert的路径

 https://gyazo.com/2e8714546606b796b63f5b64663cab31 

它安装的file.exe

 https://gyazo.com/5d0d3d5723c52e6cc812d72202ba4038 

我的模特

 has_attached_file :image, styles: { medium: "300x300>"} validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/ 

这可能有点晚了。 很多有这个问题的人正在运行Windows。

  1. Image Magick应正确安装(安装期间选择所有选项)。 这是重新安装和重新启动的重要一步,所以请将此选项保留到最后。
  2. 打开config/environments/development.rb
  3. 添加以下行:`Paperclip.options [:command_path] =’C:\ Program Files(x86)\ GnuWin32 \ bin’。 您可以通过在命令行运行which convert检查路径(显示我的路径)。 不是Windows附带的命令行。 我运行git bash。
  4. 重新启动Rails服务器
  5. 检查你的模型。 我在app \ models \ post.rb中的语法是has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }

我改成了

has_attached_file :image, style: { :medium => "300x300>", :thumb => "100x100>" }

  1. 您可能会发现错误消失,但图像未显示。 检查显示页面中的代码。
    • 如果我删除(:medium)图像显示正常。
    • 当我离开下面的代码时它没有显示(哈姆,对不起!)

= image_tag @recipe.image.url(:medium), class: "recipe_image"