attachment_fu plugin is the complete package in handling images for your website. It handles image upload, resize, generate thumbnails, storing image info to database and saving the file to physical disk drive
to install attachment_fu, we type
~$ .script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
if you don't have imagemagick and rmagick installed
~$ sudo apt-get install imagemagick
~$ dpkg -l | grep magick
~$ sudo apt-get install libmagick9-dev
~$ sudo gem install rmagick -v=1.15.12
window users: you can go download the imagemagick executable and install rmagick by doing gem install rmagick -v=1.15.12
now let's generate a model to test it out
~$ .script/generate model photo
open up the migration file and enter the following
class CreatePhotos < ActiveRecord::Migration
def self.up create_table :photos do |t|
t.column :user_id, :integer
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
end
end
def self.down
drop_table :photos end
end
:user_id - I'm assuming these photos belong to someone, you can replace it with another model_id depending on the relationship
:parent_id - don't touch, it's reserved for attachment_fu
:content_type - specify the content type of your data, default is image, but it can also be audio, or video the rest are pretty self explanatory, and we'll revisit these fields in a moment. now save your file, and do a quick rake db:migrate
J
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment