纸夹错误而确定内容类型:可卡因:: CommandNotFoundError Rails中3.2.1

2019-10-19 07:12发布

我试图用给定的代码在这里上传和使用Paperclip.I裁剪图像很能上传图片,也图像被裁切,但没有选择区域。 控制台提供了以下错误:

[纸夹]错误而确定内容类型:可卡因:: CommandNotFoundError

我曾尝试对SO像其他文章给出解决方案, 这个和这个 ,但没有人解决了这个问题。

任何其他的建议是最欢迎。

注:我的工作在Windows 7上安装的宝石有:

宝石“轨道”,“3.2.1”

保存“mysql2”

宝石“回形针”

宝石“mini_magick”

User.rb

require 'mini_magick'
class User < ActiveRecord::Base
#Paperclip.options[:command_path] = "C:\Program Files\ImageMagick-6.8.8-Q8"
#  The foll line works
#  has_attached_file :avatar,:styles => {:thumb => "75x75#",:small => "150x150>"} 

  attr_accessible :name,:email,:avatar,:crop_x,:crop_y,:crop_w,:crop_h
  has_attached_file :avatar,:styles => {:thumb => "75x75>",:small=>"100x100#", :large=>"500x500>"}#,:processors => [:cropper]
  attr_accessor :processing, :crop_x,:crop_y,:crop_w,:crop_h
  after_update :reprocess_avatar,:if=>:cropping?                       

  def cropping?
    !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
  end

  def avatar_geometry(style = :original)
    @geometry ||= {}
    @geometry[style] ||= Paperclip::Geometry.from_file(avatar.path(style))
  end

  private

  def reprocess_avatar
    # don't crop if the user isn't updating the photo
    # ...or if the photo is already being processed
     return unless (cropping? && !processing)
     self.processing = true
     avatar.reprocess!
     self.processing = false
  end   

end

users_controller.rb

 def create
  @user = User.new(params[:user])
  if @user.save
    if params[:user][:avatar].blank?
      flash[:notice] = "Successfully created user."
      redirect_to @user
    else
      render :action => "crop"
    end
  else
    render :action => 'new'
  end
end


  # PUT /users/1
  # PUT /users/1.json
  def update
    @user = User.find(params[:id])
  if @user.update_attributes(params[:user])
    if params[:user][:avatar].blank?
      flash[:notice] = "Successfully updated user."
      redirect_to @user
    else
      render :action => "crop"
    end
  else
    render :action => 'edit'
  end

 end

crop.html.erb

<% content_for(:head) do %>

<link rel="stylesheet" href="../stylesheets/jquery.Jcrop.css" type="text/css" />
<link rel="stylesheet" href="../stylesheets/jquery.Jcrop.min.css" type="text/css" />
<script src="../javascripts/jquery.min.js"></script>
<script src="../javascripts/jquery.Jcrop.js"></script>

<script type="text/javascript " charset="utf-8">
$(function() {
  $('#cropbox').Jcrop({
    onChange: update_crop,
    onSelect: update_crop,
    setSelect: [0, 0, 500, 500],
    aspectRatio: 1
  });
});

function update_crop(coords) {
  var rx = 100/coords.w;
  var ry = 100/coords.h;
  $('#preview').css({
    width: Math.round(rx * <%= @user.avatar_geometry(:large).width %>) + 'px',
    height: Math.round(ry * <%= @user.avatar_geometry(:large).height %>) + 'px',
    marginLeft: '-' + Math.round(rx * coords.x) + 'px',
    marginTop: '-' + Math.round(ry * coords.y) + 'px'
  });
  var ratio = <%= @user.avatar_geometry(:original).width %> / <%= @user.avatar_geometry(:large).width %>;
  $("#crop_x").val(Math.round(coords.x * ratio));
  $("#crop_y").val(Math.round(coords.y * ratio));
  $("#crop_w").val(Math.round(coords.w * ratio));
  $("#crop_h").val(Math.round(coords.h * ratio));
}
</script>
<% end %>

<%= image_tag @user.avatar.url(:large), :id => "cropbox" %>

<h4>Preview:</h4>
<div style="width:100px; height:100px; overflow:hidden">
  <%= image_tag @user.avatar.url(:large), :id => "preview" %>
</div>

<% form_for @user do |f| %>
  <% for attribute in [:crop_x, :crop_y, :crop_w, :crop_h] %>
    <%= f.hidden_field attribute, :id => attribute %>
  <% end %>
  <p><%= f.submit "Crop" %></p>
<% end %>

配置/ development.rb

 Paperclip.options[:swallow_stderr] = false
  Paperclip.options[:command_path] = "C:/Program Files/ImageMagick-6.8.8-Q8/"

Answer 1:

这很可能是因为回形针4使用file命令来确定文件的内容类型。 该命令不可用正常的Windows机器上。

无论是下载的Win32版本file的命令,并把它放在搜索路径。 (我使用的GnuWin32 )或者,您也可以使用回形针3.x版本。



文章来源: paperclip Error while determining content type: Cocaine::CommandNotFoundError in Rails 3.2.1