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 6232869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:11:39+00:00 2026-05-24T10:11:39+00:00

I am facing an embarrassing issue with paperclip. When calling destroy method of the

  • 0

I am facing an embarrassing issue with paperclip. When calling destroy method of the associated model. the database record is deleted , but not the attachment files.
I have seen the rails server logs, and I see the log “Deleting attachments” only, without the logs for deleting the files.

I’m using filename interpolation to rename the uploaded files (see the code).
When I delete this interpolation (removing :path & :url from the model) I notice that destroy method is working correctly. So I am sure of the root cause : filename interpolation.
am I using interpolation in a wrong way? is it a known issue in paperclip?

:path =>       ":rails_root/public/system/:attachment/:id/:style/:normalized_photo_file_name.:extension",
:url => 
"/system/:attachment/:id/:style/:normalized_photo_file_name.:extension" 


  Paperclip.interpolates :normalized_photo_file_name do |attachment, style|
    attachment.instance.normalized_photo_file_name
  end

   def normalized_photo_file_name
     if @rnd.nil? 
        @rnd= SecureRandom.hex(4)  
    end
    "photo_#{@rnd}" 

  end
  • 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-24T10:11:40+00:00Added an answer on May 24, 2026 at 10:11 am

    Yes, you are. Interpolations are supposed to be reproductible, they should yield exactly the same value for every call for a specific controller and in your case you’re generating the random value on all calls.

    When the object is destroyed, the interpolation will be called again, it will generate a different random value and it isn’t going to find this new file. If you really want to have this hex value, generate and store it in your model or instead of using a random use a hashing algorithm like a digest. Here’s how it would look like:

    #put this somewhere
    require 'digest/md5'
    
    def normalized_photo_file_name
        "photo_#{Digest::MD5.hexdigest(self.id.to_s)}" 
    end
    

    This guarantees the same value will be generated for all models and your destroy method is going to behave correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im facing an issue which I believe to be VAO-dependant, but Im not sure..
I am facing a strange issue in my Zend Application: My model is like
I am facing strange issue on Windows CE: Running 3 EXEs 1)First exe doing
Facing some problems with jQuery selectors. My HTML is like: <form method= action=> <p
im facing the challange of optimizing a database design by an automated mechanism. the
I am facing an issue that is driving me insane. I have one and
I am facing an issue regarding EF code first version while mapping one entity
Im facing a bit of an issue when trying to validate a decimal property
Im facing a strange issue trying to move from sql server to oracle. in
we are facing a strange issue. we have a (custom)file upload control in our

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.