post = Post.first
post.image_path #(this is a image path like http://localhost:3000/uploads/image/sd54asdf.jpg)
,如果我這樣做:
post.destroy
有了這個,我從毀滅後對象中的每個屬性,包括圖像。
我可以在不刪除圖像的情況下刪除對象嗎?
誰能告訴我這是否可能?
用這種方法,我檢查是否是圖像引用的最後一個對象。
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
如果發佈has_one圖像,然後使用刪除而不是銷燬將完成這項工作。 – 2012-02-09 10:51:32
謝謝@AlokSwain,你能幫我一個例子嗎?謝謝:D – hyperrjas 2012-02-09 11:00:46
隨着刪除方法不刪除圖像,它確實工作正常。這是對的?謝謝你@AlokSwain – hyperrjas 2012-02-09 12:01:59