上传多个文件上传参阅了
http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
http://www.flex888.com/2007/03/23/multiple-file-upload-with-ruby-on-rails-acts_as_attachment.html
http://www.flex888.com/2007/03/23/multiple-file-upload-with-ruby-on-rails-acts_as_attachment.html
其本上以最下面的为主,我主要用RMagick ,filecolumn,然后是上面连接中的 cool multiple file upload JavaScript 下面是是上面文章中的一段截取
First of all, go here to download the cool multiple file upload JavaScript so that you can have the dynamic file list built up for uploading, like this:
根据上面的提示下载好uplad javascript
放在自己的工程里,关于rmargick,filecolumn文件上传的搭配参考再建rmargick filecoumn一文,网上也比较多,
好了之后在view中加入
- "my_file_element" type="file" name="file_1" >
- #在controller中加入
- i = 0
while @params["file_"+i.to_s] != "" and i <=2
p = Hash["entry"=>{"image"=>""}]
p["entry"]["image] = params["file_"+i.to_s] if i != 0
@entry = Entry.create!(p["entry"])
i += 1
end
就可以了,就可以实件文件上传了 - 如果你要一表多字段的话只要修改上面的代码就可以了,然后在 entry中
- file_column :image, :magick => {
:versions => { "thumb" => "50x50", "medium" => "640x480>" }
}
file_column :image1, :magick => {
:versions => { "thumb" => "50x50", "medium" => "640x480>" }
} - 增加相应的字段就可以了
此文多半属于抄阅,记下以便学习,请参考上面连接
关于如何使用file column 请参考
http://wiki.rubyonrails.org/rails/pages/HowToUseFileColumn