Class: Notee::Image

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/notee/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject

Returns the value of attribute file.



5
6
7
# File 'app/models/notee/image.rb', line 5

def file
  @file
end

Instance Method Details

#manage_imageObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/notee/image.rb', line 8

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