`
danny.chiu
  • 浏览: 88944 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Rails Paperclip and ImageMagick

阅读更多
 在网上找了关于paperclip的有关插件,发现按他们说的,设置了大小却没有效果,后来发现需要安装一个图像编辑的软件才行:ImageMagick

下面简单的介绍一下:
环境:Windows + Cygwin + Rails
向项目中的Person类添加上传附件功能

一、安装paperclip:
script/plugin install git://github.com/thoughtbot/paperclip.git

迁移任务:
script/generate paperclip person photo
rake db:migrate

在model/Person.rb中加入:
class Person < ActiveRecord::Base
	has_attached_file :photo, :styles => { 
		:thumb => "100x100#",
		:small => "150x150>",
		:large => "400x400>" },
      :url  => "/assets/products/:id/:style/:basename.:extension",
      :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
end

在views/people下的new.html.erb和edit.html.erb中修改form并加入:
<% form_for @person, :html => { :multipart => true } do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :photo %><br />
    <%= f.file_field :photo %>
  </p>
<% end %>

在views/people下的index.html.erb和show.html.erb中加入:
<%= image_tag person.photo.url(:thumb) %>
<%= image_tag person.photo.url(:small) %>
<%= image_tag person.photo.url(:large) %>

不过现在上传了图片还不能正确的显示出来,还需要:

二、安装ImageMagick
详见:http://www.imagemagick.org/script/install-source.php#unix
大致是先下载ImageMagick.tar.gz到Cygwin目录下,解压编译安装:
tar xvfz ImageMagick.tar.gz
cd ImageMagick-6.5.1
./configure
make && make install

现在就可以啦,试试吧
3
1
分享到:
评论
3 楼 danny.chiu 2009-11-30  
vwangzhen 写道
早已解决原来是windows 的原因

windows 不是理想的开发环境哈,我现在也换linux了~
2 楼 vwangzhen 2009-10-18  
早已解决原来是windows 的原因
1 楼 vwangzhen 2009-10-02  
rials 环境是什么

我这为什么老出错

# Image C:/DOCUME~1/ADMINI~1.534/LOCALS~1/Temp/stream.636.0 is not recognized by the 'identify' command.
# Image C:/DOCUME~1/ADMINI~1.534/LOCALS~1/Temp/stream.636.0 is not recognized by the 'identify' command.

相关推荐

Global site tag (gtag.js) - Google Analytics