Sha256: 7f2ce3791ce758cef66b4aac7acaa5ce59a301bcabffb4aca81400c84b679a43

Contents?: true

Size: 864 Bytes

Versions: 3

Compression:

Stored size: 864 Bytes

Contents

class Photo < ActiveRecord::Base
  include Positionable
  default_scope order(:position)

  validates_attachment :image, :presence => true,
    :size => { :in => 0..5.megabytes }

  has_attached :image
  
  acts_as_taggable

  validates_presence_of :photographable
  belongs_to :photographable, :polymorphic => :true
  delegate :url, :file_name, :to => :image
  
  field :caption, :text
  
  def owner
    photographable.owner if photographable && photographable.respond_to?(:owner)
  end
    
  timestamps

  def to_label
    image_file_name
  end
  
  # ============
  # = Rotation =
  # ============

  attr_accessor :rotation_degrees, :rotate
    
  def rotate!(degrees = 90)
    self.rotation_degrees ||= degrees
    self.rotate = true
    self.image.reprocess!
    self.save
  end
  
  def rotating?
    !self.rotation_degrees.nil? and self.rotate
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fullstack-cms-0.3.33 app/models/photo.rb
fullstack-cms-0.3.32 app/models/photo.rb
fullstack-cms-0.3.31 app/models/photo.rb