Sha256: 1a9f83d99a6d0acb011598e9488336a2b3a8c3078beb563406ac431da91f771f

Contents?: true

Size: 1013 Bytes

Versions: 2

Compression:

Stored size: 1013 Bytes

Contents

class SpudBanner < ActiveRecord::Base
  belongs_to :owner, :class_name => 'SpudBannerSet', :foreign_key => 'spud_banner_set_id', :inverse_of => :banners, :touch => true

  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,
    :s3_host_name => Spud::Banners.s3_host_name,
    :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

2 entries across 2 versions & 1 rubygems

Version Path
spud_banners-1.0.0 app/models/spud_banner.rb
spud_banners-1.0.0.rc1 app/models/spud_banner.rb