Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Asset < ActiveRecord::Base
- has_attached_file :media,
- :storage => :s3,
- :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
- :path => ":attachment/:id/:style.:extension",
- :bucket => S3_BUCKET,
- :styles => {:thumb => "75x75>", :large => "600x800>",
- :whiny => false,
- :default_url => "/images/:attachment/missing.jpg"
- def thumbnail_uri(style = :original)
- if style == :original || has_thumbnail?
- attachment.s3.interface.get_link(attachment.s3_bucket.to_s, attachment.path(style), EXPIRES_AFTER)
- else
- generic_icon_path style
- end
- end
- # Generates a path to the thumbnail image for the given content type
- # and image size.
- #
- # e.g. a :small thumbnail with a content type of text/html, the file name
- # would have the filename icon.small.text.html.png
- #
- # If no such thumbnail can be found a generic one is returned
- def generic_icon_path(style = image.default_style)
- url = "/images/attachments/icon.#{style.to_s}.#{attachment_content_type.sub('/', '.')}.png"
- if File.exists? "#{RAILS_ROOT}/public/#{url}"
- url
- else
- "/images/attachments/icon.#{style.to_s}.default.png"
- end
- end
- icon.small.application.msword.png
- icon.small.text.plain.png
- icon.small.application.vnd.ms-excel.png
- icon.small.application.vnd.openxmlformats-officedocument.spreadsheetml.sheet.png
- icon.small.application.vnd.openxmlformats-officedocument.wordprocessingml.document.png
- icon.small.default.png
Add Comment
Please, Sign In to add comment