Sha256: a1f14f5db1cc1a9f1c1129bf502ab14dcdb72ac72f91a102a0212a7b1c46a1f1

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

class SpudBanner < ActiveRecord::Base
  attr_accessible :banner, :link_to, :link_target, :title, :alt, :sort_order, :rich_text
  belongs_to :owner, :class_name => 'SpudBannerSet', :foreign_key => 'spud_banner_set_id', :inverse_of => :banners

  has_attached_file :banner, 
    :styles => lambda { |attachment| attachment.instance.dynamic_styles },
    :convert_options => {
      :admin_small => '-strip -density 72x72',
      :banner => '-strip -density 72x72'
    },
    :storage => Spud::Banners.paperclip_storage,
    :s3_credentials => Spud::Banners.s3_credentials,
    :url => Spud::Banners.storage_url,
    :path => Spud::Banners.storage_path

  validates_attachment_presence :banner

  def dynamic_styles
    styles = {
      :spud_admin_small => '300x150'
    }
    owner_style = nil
    if self.owner
      owner_style = "#{self.owner.width}x#{self.owner.height}"
      owner_style += '#' if self.owner.cropped
      styles[:banner] = owner_style
    end
    return styles
  end

  def set_name
    return owner.name
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_banners-1.0.2 app/models/spud_banner.rb
tb_banners-1.0.1 app/models/spud_banner.rb
tb_banners-1.0 app/models/spud_banner.rb