Skip to content

Instantly share code, notes, and snippets.

@mkrogh
Created March 3, 2012 00:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mkrogh/1963073 to your computer and use it in GitHub Desktop.
Save mkrogh/1963073 to your computer and use it in GitHub Desktop.
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