I am trying to delete a few things before the actual delete of the object occurs. (I am using paperclip) So I thought before_destroy is my solution. I don't want to use dependent destroy. ( some reasons) I have a model like this :
class Picture < ActiveRecord::Base
belongs_to :user
has_attached_file :image, :styles => {:d800x2400 =>"800x2400>",:d220x150=>"220x150#",:d118x118 => "118x118#",:d60x60=>"60x60#"}
before_destroy :remove_extras
after_save : add_extras
private
def ad开发者_如何学JAVAd_extras
logger.info " adding extras "
puts image.url(:d60x60)
end
def remove_extras
logger.info " Removing extras "
puts image.url(:d60x60)
end
Now The output which I get is (while adding & then deleting):
adding extras
/system/images/186/d60x60/something.png
deleting extras
/system/images/d60x60/missing.png
Can someone tell me why I am unable to get the proper url ?
You probably already have an answer to this, but in case you don't:
The problem is that you need your "before_destroy" to come BEFORE the "has_attached_file" part... Otherwise, Paperclip's own "before_destroy" gets called first and kills the image before your method gets called...
I just got this problem myself and changing the order of declarations fixed it.
精彩评论