file-column学习

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

   class Entry < ActiveRecord::Base
        file_column :image
    end
#在model中指定一个要上传的字段

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

    <%= file_column_field "entry", "image" %>
#在view中显示上传表单,
... and display uploaded images in your view:

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

#在view中显示上传文件

3、To resize every uploaded image to a maximum size of 640x480, you just have to declare an additional option.

    class Entry < ActiveRecord::Base
        file_column :image, :magick => { :geometry => "640x480>" }
    end
#设置上传文件大小为640X480
4、
You can even automatically create versions in different sizes that have nice filenames...
    class Entry < ActiveRecord::Base
        file_column :image, :magick => {
          :versions => { "thumb" => "50x50", "medium" => "640x480>" }
        }
    end

#建产一个versions,使每个不同大小的文件有不同的大小,如thumb=>"50X50","medium"=>"640X480"
  <%= image_tag url_for_file_column 'entry', 'image' %>  
  #显示为原来大小
  <%= image_tag url_for_file_column 'entry', 'image' ,'thumb'%>
  #大小为thumb("50X50")
  <%= image_tag url_for_file_column 'entry', 'image' ,'medium'%>
  #大小为medium("640X480")

你可能感兴趣的:(ActiveRecord)