hyperrjas
unread,Feb 8, 2012, 7:48:31 PM2/8/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to carrierwave
I have one original object post.rb with the next fields or attributes.
class Post
include Mongoid::Document
mount_uploader :posted, PostedUploader, mount_on: :posted_filename
field :posted
field :remote_posted_url
attr_accessible :posted, :remote_posted_url
end
Then I want create a copy from the first original object and share
images for the new object. Then I doing:
attribs = @post.attributes.select {|a| %w(posted
remote_posted_url).include? a }
new_post = Post.new attribs
new_post.save
So far, everything works fine the new object, share the images of the
original. The two objects have the same shared image with the same
path.
The problem is if I delete the original object, the clone object can
not find the image because I deleted in original post.
How can I, in my destroy action object, with a callback
before_destroy, check whether the image is used by one or more
objects.
if the image, using 2 or more objects, Not delete the image.
Otherwise, if the image is used by a single object, Delete the image.
Its possible?
I'm need a method to verify this problem.