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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:19:03+00:00 2026-05-29T11:19:03+00:00

eg. post = Post.first post.image_path #(this is a image path like http://localhost:3000/uploads/image/sd54asdf.jpg) if I

  • 0

eg.

post = Post.first

post.image_path #(this is a image path like http://localhost:3000/uploads/image/sd54asdf.jpg)

if I doing:

post.destroy

With this, I destroy every attributes from post object including the image.

Can I delete object without delete the image?

Can anyone tell me if this is possible?

With this method, I check if is the last object referenced by the image.

def validates_image_dependents
  post = self.find(params[:id])
   i=0
  for this_post in Post.all
   if this_post.posted_filename == post.post_filename
    i+=1
   end
  end
 return i > 1
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-29T11:19:04+00:00Added an answer on May 29, 2026 at 11:19 am

    Calling destroy on a record is going to delete all data relating to that record. I think that you have 3 options:

    1. Make an associated object that contains information about the image and do not set up Rails to delete the associated records when a Post is deleted
    2. I suspect this is more like what you’re trying to achieve – Instead of destroying objects you may still need to reference, update the Post model to have a boolean that tracks whether the record is “deleted” and then use this to only retrieve active posts. This is soft-deleting and is very common where complex associations make it hard to totally delete records
    3. Set up the destroy action to create some sort of archived post record that you can use to access the attributes you still require

    I like option 2 but it depends on exactly what you’re trying to achieve.

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

Sidebar

Related Questions

I'm trying to upload image to Amazon S3 with this Ruby code: require 'net/http/post/multipart'
My first post here, so i hope this is the right area. I am
This is my first post here and I wanted to get some input from
This is my first post and I'm quite a novice on C++ and compiling
This is my first post on Stack Overflow and I'm just wondering on the
SOLVED! Used this example from php.net post method handling multiple uploads, with the knowledge
This is my first post to Stack Overflow so please forgive me if I
Hi Everyone (this is my first post), I am trying to figure a way
This is my first post, so let me start by saying HELLO! I am
This is my first SO post, forgive me if my formatting stinks. I'm trying

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.