Sha256: 74750f294a65b3691ff4c46a33e880c9bbe26cd34a8d173a4e6a23ccc08838de

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module Humpyard
  module Assets
    class PaperclipAsset < ::ActiveRecord::Base
      attr_accessible :media
    
      acts_as_humpyard_asset :system_asset => true
    
      # ToDo render styles - not working for non-images like mp3
    
      begin
        has_attached_file(
          :media, 
          :default_style => :original,
          #:styles => {:preview => ['500x500>', :jpg], :thumb => ['200x100>', :jpg]},
          :path => ":rails_root/public/system/media/:id/:basename.:extension",
          :url => "/system/media/:id/:basename.:extension"
        )
        validates_attachment_presence :media
        after_post_process :update_media_dimensions
      rescue
        puts "Paperclip not usable."
      end
    
      def title
        media_file_name
      end
    
      def url
        media.url
      end
      
      def content_type
        media_content_type
      end
    
      def update_media_dimensions
        begin
          size = Paperclip::Geometry.from_file media.queued_for_write[:original]
          asset.width = size.width.to_i
          asset.height = size.height.to_i
        rescue
          asset.width = nil
          asset.height = nil
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
humpyard-0.0.1 app/models/humpyard/assets/paperclip_asset.rb