Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 292613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:11:46+00:00 2026-05-12T06:11:46+00:00

I’m using Paperclip with a Ruby on Rails to attach assets to a model,

  • 0

I’m using Paperclip with a Ruby on Rails to attach assets to a model, these assets can be any file type and currently thumbnails are only being generated if the asset is an image. I’d like to be able to display a different default image for other files, either by generating a thumbnail of the files on upload, or setting something up with the default_url but so far I can’t find any resources to help with this and am getting no where on my own.

My model is as follows:

  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"  

Does anyone have any resources for generating custom thumbnails if generation fails, or fall back on something like :content_type in the default url? I’ve looked through the source and haven’t been able to get anywhere.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:11:46+00:00Added an answer on May 12, 2026 at 6:11 am

    I’ve actually implemented this very same feature. Paperclip generates thumbnails for all my images and PDFs, and I have added custom thumbnail icons for MS Word, Excel, HTML, TXT files etc.

    My solution is fairly straightforward. In my model Attachment (in your case Asset) I have defined the following method:

    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
    

    This returns either a URL to a thumbnail stored on S3, or a local path to a generic PNG icon based on the assets content type (discussed below). The has_thumbnail? method determines whether or not this asset has had a thumbnail generated for it. This is something I added in my own fork of Paperclip, but you can substitute in your own logic (I’m not sure of the ‘standard’ way to determine this, maybe comparing the path with your defined ‘missing’ path, or even just comparing the content type to a default list [“image/jpeg”, “image/png”] etc).

    Anyway, here’s the method which passes back a path to a generic icon based on both the thumbnail style (in your case :thumb and :large) and the content type:

    # 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
    

    Then, to add a new thumbnail I just add PNG files into /images/attachments/ with the correct file name convention. My thumbail style is called :small and I have defined styles for Word, Excel and plain text so at the present time I have:

    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
    

    If the content type isn’t supported, there’s a generic ‘catch all’ icon which is displayed:

    icon.small.default.png
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 168k
  • Answers 168k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer More like a 6-liner, but you can use commons-email: import… May 12, 2026 at 1:46 pm
  • Editorial Team
    Editorial Team added an answer The IDE fix pack does help with Error Insight problems,… May 12, 2026 at 1:46 pm
  • Editorial Team
    Editorial Team added an answer It works for me if you use the html tag… May 12, 2026 at 1:46 pm

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.