Created
March 3, 2012 00:51
-
-
Save mkrogh/1963073 to your computer and use it in GitHub Desktop.
Carrierwave proccess zipfile contents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A nice little carrierwave IO faker class | |
class FilelessFile < StringIO | |
attr_accessor :original_filename | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#.... | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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