Thursday, June 22, 2006

Plugin: file_column

This is straight from the "file_column website":http://www.kanthak.net/opensource/file_column/:

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


class Entry < ActiveRecord::Base
file_column :image
end


... 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") %>

However, you may want to protect against the model object having no uploaded image:

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


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


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


... and display them in your view:


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


0 Comments:

Post a Comment

<< Home