回形针接受生产的jpg和png

Tam*_*Tam 4 ruby-on-rails passenger paperclip

我在我的Rails应用程序中使用PaperClip插件,如下所示:

  has_attached_file :photo, :styles => {:small => '64X64>', :medium => '250X250>'},
                                      :url  => "/assets/user_photos/:id/:style/:basename.:extension",
                                      :path => ":rails_root/public/assets/user_photos/:id/:style/:basename.:extension"
#  validates_attachment_presence :photo
  validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png','image/gif']
  validates_attachment_size :photo, :less_than => 1.megabytes
Run Code Online (Sandbox Code Playgroud)

它在开发上运行良好(Mac OSX + Mongrel).但是当我把它投入生产时(Linux Debian + Apache/Passenger)它只接受.gif并且我得到以下错误:.png和.jpg:

 Photo /tmp/stream20091028-20066-1t1a0oz-0 is not recognized by the 'identify' command.
 Photo /tmp/stream20091028-20066-1t1a0oz-0 is not recognized by the 'identify' command.
Run Code Online (Sandbox Code Playgroud)

我尝试添加以下行作为一些教程建议,但它没有帮助!

Paperclip.options[:command_path] = "/usr/local/bin"
Run Code Online (Sandbox Code Playgroud)

ben*_*sie 5

在生产服务器上,尝试运行:

which identify
Run Code Online (Sandbox Code Playgroud)

这应该为您提供ImageMagick标识二进制文件的路径 - 如果不是,您没有安装ImageMagick或者它不在您的路径中.

如果它返回类似"/ usr/bin/identify"的内容,那么您需要将production.rb环境文件中的Paperclip选项设置为:

Paperclip.options[:command_path] = "/usr/bin"
Run Code Online (Sandbox Code Playgroud)