Class: Notee::Image
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Notee::Image
- Defined in:
- app/models/notee/image.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
Instance Attribute Details
#file ⇒ Object
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_image ⇒ Object
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 |