Guest User

Untitled

a guest
May 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. class Asset < ActiveRecord::Base
  2. has_attached_file :media,
  3. :storage => :s3,
  4. :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
  5. :path => ":attachment/:id/:style.:extension",
  6. :bucket => S3_BUCKET,
  7. :styles => {:thumb => "75x75>", :large => "600x800>",
  8. :whiny => false,
  9. :default_url => "/images/:attachment/missing.jpg"
  10.  
  11. def thumbnail_uri(style = :original)
  12. if style == :original || has_thumbnail?
  13. attachment.s3.interface.get_link(attachment.s3_bucket.to_s, attachment.path(style), EXPIRES_AFTER)
  14. else
  15. generic_icon_path style
  16. end
  17. end
  18.  
  19. # Generates a path to the thumbnail image for the given content type
  20. # and image size.
  21. #
  22. # e.g. a :small thumbnail with a content type of text/html, the file name
  23. # would have the filename icon.small.text.html.png
  24. #
  25. # If no such thumbnail can be found a generic one is returned
  26. def generic_icon_path(style = image.default_style)
  27. url = "/images/attachments/icon.#{style.to_s}.#{attachment_content_type.sub('/', '.')}.png"
  28. if File.exists? "#{RAILS_ROOT}/public/#{url}"
  29. url
  30. else
  31. "/images/attachments/icon.#{style.to_s}.default.png"
  32. end
  33. end
  34.  
  35. icon.small.application.msword.png
  36. icon.small.text.plain.png
  37. icon.small.application.vnd.ms-excel.png
  38. icon.small.application.vnd.openxmlformats-officedocument.spreadsheetml.sheet.png
  39. icon.small.application.vnd.openxmlformats-officedocument.wordprocessingml.document.png
  40.  
  41. icon.small.default.png
Add Comment
Please, Sign In to add comment