Sha256: fe110f281043f916c7e471c86f3863433181833207795fabe209f39eea1ccdd7

Contents?: true

Size: 591 Bytes

Versions: 8

Compression:

Stored size: 591 Bytes

Contents

require 'securerandom'

module Notee
  class Image < ActiveRecord::Base
    attr_accessor :file
    before_save :manage_image

    def manage_image
      return unless self.file

      image_dir = Rails.root.to_s + "/public/notee"
      FileUtils.mkdir_p(image_dir) unless FileTest.exist?(image_dir)

      image_name = Time.now.strftime('%Y%m%d%H%M%S') + '--' + SecureRandom.uuid + '.jpg'
      self.transaction do
        open(image_dir + "/" + image_name, 'wb') do |output|
          output.write(self.file.read)
        end
        self.content = image_name
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
notee-0.2.8 app/models/notee/image.rb
notee-0.2.7 app/models/notee/image.rb
notee-0.2.6 app/models/notee/image.rb
notee-0.2.5 app/models/notee/image.rb
notee-0.2.4 app/models/notee/image.rb
notee-0.2.2 app/models/notee/image.rb
notee-0.2.1 app/models/notee/image.rb
notee-0.2.0 app/models/notee/image.rb