Reputation: 10744
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
Upvotes: 0
Views: 249
Reputation: 2478
Calling destroy on a record is going to delete all data relating to that record. I think that you have 3 options:
I like option 2 but it depends on exactly what you're trying to achieve.
Upvotes: 1