RMAGIC和file_column整合

file_column是一款相当不错的,用于上传文件,生成缩略图的一款ROR插件
下面介绍使用方法

安装为组件

./script/plugin install http://opensvn.csie.org/rails_file_column/ plugins/file_column/trunk

在model里修改

validates_format_of :image,  
    :with=>/^.*(.jpg|.JPG|.gif|.GIF)$/,  
    :message => "你只能上传JPG或则GIF的图片文件"  
  file_column :image, :magick => {   
         :versions => { "thumb" => "50x50", "medium" => "640x480>" }  
     }  

注意上传文件会出错,有时是因为少了这句<%= start_form_tag 'create',:multipart => true%>  





Just make the "image" column ready for handling uploaded files...

    class Entry < ActiveRecord::Base         file_column :image     end     

在view里修改:

... generate file fields that keep uploaded images during form redisplays to your view...

    <%= file_column_field "entry", "image" %>     

... and display uploaded images in your view:

    <%= image_tag url_for_file_column("entry", "image") %>     

注意在数据库中,因为要生成缩小图,所以必须在 pic blob not null后加入 pic_temp blob not null一句。

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值