Sha256: d9fd223ed2f967b43bfc04625ed70022d48648a57d3601af39ddc21dbc92cebb
Contents?: true
Size: 671 Bytes
Versions: 9
Compression:
Stored size: 671 Bytes
Contents
module Thredded class Image < ActiveRecord::Base mount_uploader :image, ImageUploader validates :image, presence: true before_validation :save_dimensions, :save_orientation, :save_position private def save_dimensions if image.path self.width = MiniMagick::Image.open(image.path)[:width] self.height = MiniMagick::Image.open(image.path)[:height] end end def save_orientation if image.path self.orientation = (height.to_i > width.to_i) ? 'portrait' : 'landscape' end end def save_position self.position = (self._index + 1) if self.new_record? and self._index end end end
Version data entries
9 entries across 9 versions & 1 rubygems