Ruby on rails 3.2 确定内容类型时出现回形针错误:Rails 3.2.1中的Cokine::CommandNotFoundError
我尝试使用给出的代码上传和裁剪图像使用回形针。我可以上传图像,图像也被裁剪,但没有选择区域。控制台出现以下错误: [回形针]确定内容类型时出错:Cokine::CommandNotFoundError 我尝试过其他类似和的文章给出的解决方案,但没有一篇解决了这个问题 任何其他建议都是非常受欢迎的 注意:我正在Windows 7上工作。 安装的GEM包括: gem“rails”、“3.2.1” gem'mysql2' 宝石“回形针” 宝石“迷你魔术” User.rbRuby on rails 3.2 确定内容类型时出现回形针错误:Rails 3.2.1中的Cokine::CommandNotFoundError,ruby-on-rails-3.2,paperclip,minimagick,Ruby On Rails 3.2,Paperclip,Minimagick,我尝试使用给出的代码上传和裁剪图像使用回形针。我可以上传图像,图像也被裁剪,但没有选择区域。控制台出现以下错误: [回形针]确定内容类型时出错:Cokine::CommandNotFoundError 我尝试过其他类似和的文章给出的解决方案,但没有一篇解决了这个问题 任何其他建议都是非常受欢迎的 注意:我正在Windows 7上工作。 安装的GEM包括: gem“rails”、“3.2.1” gem'mysql2' 宝石“回形针” 宝石“迷你魔术” User.rb require 'mini_m
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
crop.html.erb
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
<% 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 %>
Paperclip.options[:swallow_stderr] = false
Paperclip.options[:command_path] = "C:/Program Files/ImageMagick-6.8.8-Q8/"
这很可能是因为曲别针4使用
文件
命令来确定文件的内容类型。该命令在普通Windows计算机上不可用
下载Win32版本的
文件
命令,并将其放在搜索路径中的某个位置。(我正在使用)或者你可以使用3.x版本的回形针 我用attr_访问器尝试了相同的错误,你能检查一下这个尝试过的吗。。错误保持不变!!