<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=706355809571598&amp;ev=PageView&amp;noscript=1">
Free Assessment
Estimate Project
Menu
Estimate Project

HTML5 multi upload with paperclip: The easy way

by Yannick S., on 14 April 2012

If you sometimes need to attach many files to a rails model, we find on the web a lot of tutos with uploadify and so on. Here is a simple way to do it only with HTML5, paperclip and rails.

attachment.rb
1
2
3
4
class Attachment < ActiveRecord::Base
 belongs_to :note
 has_attached_file :attachment
end
note.rb
1
2
3
4
5
6
7
8
class Note < ActiveRecord::Base
 has_many :attachments
 def attachments_array=(array)
 array.each do |file|
 attachments.build(:attachment => file)
 end
 end
end

With only that little of HTML5 magic, we can upload has many files that we want only by adding this input file in the note form.

note_form.html
1
<input type=file name=attachments_array multiple />

New Call-to-action

 
Topics:Under the hood

Comments