Ruby on rails 3 红宝石导轨、回形针;识别;命令在cmd中工作,但在app中不工作
我已经在我的Windows7 64位上安装了ImageMagick,我还有回形针宝石。我的用户模型如下所示:Ruby on rails 3 红宝石导轨、回形针;识别;命令在cmd中工作,但在app中不工作,ruby-on-rails-3,imagemagick,paperclip,Ruby On Rails 3,Imagemagick,Paperclip,我已经在我的Windows7 64位上安装了ImageMagick,我还有回形针宝石。我的用户模型如下所示: class User < ActiveRecord::Base # Paperclip has_attached_file :photo, :styles => { :thumb=> "100x100#", :small => "150x150>" } end <%= form_for(@u
class User < ActiveRecord::Base
# Paperclip
has_attached_file :photo,
:styles => {
:thumb=> "100x100#",
:small => "150x150>" }
end
<%= form_for(@user, :html => { :multipart => true } ) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username %>
</div>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :crypted_password %><br />
<%= f.text_field :crypted_password %>
</div>
<div class="field">
<%= f.label :password_salt %><br />
<%= f.text_field :password_salt %>
</div>
<%= f.file_field :photo%>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
enter code here
我的表格如下所示:
class User < ActiveRecord::Base
# Paperclip
has_attached_file :photo,
:styles => {
:thumb=> "100x100#",
:small => "150x150>" }
end
<%= form_for(@user, :html => { :multipart => true } ) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username %>
</div>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :crypted_password %><br />
<%= f.text_field :crypted_password %>
</div>
<div class="field">
<%= f.label :password_salt %><br />
<%= f.text_field :password_salt %>
</div>
<%= f.file_field :photo%>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
enter code here
{:multipart=>true})do | f |%>
禁止保存此用户:
在这里输入代码
上载图像时出现以下错误:
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: C:/Users/John/AppData/Local/Temp/stream20110212-6576-1us1cdl.png is not recognized by the 'identify' command.>
[paperclip]处理时收到错误:#
我可以在该图像的cmd中使用identify,它可以毫无问题地返回关于该图像的元数据
如果可以的话,请帮忙。我已经在这个问题上纠缠了一天多了 打开命令提示符并键入
echo%path%
您的imagemagick路径应该出现在那里
还可以尝试将
:命令路径更改为C:/Progra~1/ImageM~1
在development.rb中更新了以下内容,并开始工作
Paperclip.options[:command_path] = 'C:/Progra~1/ImageM~1.8-q'
这是在Windows 2008 32位服务器上发生的这是由于lib/Paperclip/command_line.rb
中的回形针gem中存在错误造成的
full_path
函数生成带有反斜杠的命令文件名
"C:\Program Files\ImageMagick-6.7.0-Q16"/identify
此命令在Windows上失败,因为当命令文件是带反斜杠的时,cmd
shell抛出错误
有两种方法可以解决这个问题
使用作为命令路径。
注意:您可以按如下方式获取短文件名:
dir /x "C:\Program Files*"
dir /x "C:\Program Files\ImageMagick-6.7.0-Q16*"
猴子在config\initializers\Paperclip.rb
中修补回形针宝石。
我在2.3.11测试了这个
class Paperclip::CommandLine
def full_path(binary)
[self.class.path, binary].compact.join(File::ALT_SEPARATOR||File::SEPARATOR)
end
end
现在,使用正确的路径分隔符生成identify
命令
"C:\Program Files\ImageMagick-6.7.0-Q16"\identify
我更喜欢第二种方法,因为命令路径
更容易配置
"C:\Program Files\ImageMagick-6.7.0-Q16"\identify