裝attachment_fu畀Rails用好易。
首先裝咗ImageScience先。
裝法:
$ sudo gem install image_science
跟住作去Rails嗰個App嘅目錄,裝attachment_fu
$ script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
之後,起個class table畀啲file
class CreateUploadFile < ActiveRecord::Migration
def self.up
create_table :upload_files do |t|
# 所有都用
t.string :content_type
t.string :filename
t.integer :size
# image 用
t.integer :width
t.integer :height
# thumbnail 用
t.string :thumbnail
t.integer :parent_id
# 如果揀用database儲file
t.references :db_file
end
end
def self.down
drop_table :upload_files
end
end
#如果用database儲
def CreateDbFiles < ActiveRecord::Migration
def self.up
create_table :db_files do
t.binary :data
end
end
def self.down
drop_table :db_files
end
end
係咁樣,搞掂。
個class UploadFile入便,
加has attachment同佢一堆option搞掂。
跟住係整view或controller控制。
Post a Comment