简体   繁体   English

Windows 7上的回形针+ ImageMagick:当我向模型中的attach_file添加样式时,图像显示失败

[英]Paperclip + ImageMagick on Windows 7: Image display fails when I add styles to attached_file in model

I'm working with Ruby on rails 2.3.8, NetBeans IDE. 我正在使用Ruby on Rails 2.3.8,NetBeans IDE。

I've installed paperclip and I could show/save images successfully. 我已经安装了回形针,可以成功显示/保存图像。 Now, I've installed ImageMagick-6.6.2-4-Q16(for windows 7, 64bits). 现在,我已经安装了ImageMagick-6.6.2-4-Q16(适用于Windows 7、64位)。

Until that moment, my model looked like this(and worked fine): 在那一刻之前,我的模型看起来像这样(并且运行良好):

has_attached_file :photo

Now, after installing ImageMagick, when I add the :style line it fails: 现在,在安装ImageMagick之后,当我添加:style行时,它将失败:

has_attached_file :photo,
    :styles => {:thumb => "100x100#",   :small => "150x150>",   :large => "400x400>" }

and it throws the following error message when I try to upload an image: 当我尝试上传图像时,它会引发以下错误消息:

 TypeError in ProfilesController#update

backtrace must be Array of String

The only thing I'm doing in the update action of that controller is the following: 我在该控制器的update操作中唯一要做的事情是:

  @profile.update_attributes(params[:profile])
  @profile.update_attribute(:photo, params[:profile][:photo])

I've also installed miniMagick gem(because I read somewhere I had to do it). 我还安装了miniMagick gem(因为我必须在某处阅读)。

What am I missing? 我想念什么?

I'll show you what it worked for us: 我将向您展示它对我们有用的功能:

There is a name conflict with "convert" command. 与“转换”命令存在名称冲突。 Paperclips tries to run "convert" as is, but this command is already included in the Windows installations as a filesystem converter (FAT to NTFS or something). 回形针试图按原样运行“转换”,但是此命令已作为文件系统转换器(FAT到NTFS或其他形式)包含在Windows安装中。

If you try to run "convert" from command line, probably will run the mentioned converter instead of imagemagick's "convert" It depends on the PATH environment variable. 如果您尝试从命令行运行“转换”,则可能会运行上述转换器而不是imagemagick的“转换”。这取决于PATH环境变量。

If we set imagemagick's path FIRST in the PATH variable it will resolve this path first, so the windows' command won't be executed. 如果我们在PATH变量中设置imagemagick的路径FIRST,它将首先解析该路径,因此不会执行Windows命令。

In order to fix it on our rails application, we added 为了将其修复在我们的Rails应用程序中,我们添加了

...
if Sys::Uname.sysname == "Linux"
...
else
  ....
   ENV['PATH'] = Paperclip.options[:command_path] + ";" + ENV['PATH']
end
...

on production.rb 在production.rb

尝试下载回形针版本2.3.1.1,但更高的版本对我来说却失败了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM