Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Carrierwave proccess zipfile contents
#A nice little carrierwave IO faker class
class FilelessFile < StringIO
attr_accessor :original_filename
end
#....
def create
zip_file = params[:gallery].delete(:zip_file)
@gallery = Gallery.new(params[:gallery])
if @gallery.save
#in gemfile: gem "zippy"
Zippy.each(zip_file.tempfile) do |name, file|
io = FilelessFile.new(file)
io.original_filename= name
img = Image.new(:gallery_id => @gallery.id)
img.image= io
img.save
end
end
respond_with(@gallery, :location => galleries_path)
end
class Image < ActiveRecord::Base
attr_accessible :gallery_id, :title, :image
belongs_to :gallery
mount_uploader :image, ImageUploader
validates :image, :uniqueness => {:scope => :gallery_id}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.