Forum: Ruby on Rails before_destroy not called

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9c0eebc506c56c64dc616cdf123fa671?d=identicon&s=25 Chris Chris (aboulafia)
on 2006-03-24 15:15
Hello, I'm trying to intercept delete call in my model but
before_destroy callback is never called...

Somebody knows why ?

Thanks

The controller :

def delete
    Image.delete(params[:id])
    redirect_to :action => "list"
end

The model :
class Image < ActiveRecord::Base
  set_table_name "publish_images"
  belongs_to :article
  before_destroy :on_destroy

  def delete
  end

  def on_destroy
      breakpoint # never hit this bkpoint
  end
end
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-03-24 18:00
(Received via mailing list)
before destroy is called before the destroy() method is called.  you're
not
calling destroy.

try this instead:

The controller :

def delete
   Image.destroy(params[:id])
   redirect_to :action => "list"
end

The model :
class Image < ActiveRecord::Base
 set_table_name "publish_images"
 belongs_to :article
 before_destroy :on_destroy

 private
 def on_destroy
     breakpoint # never hit this bkpoint
 end
end
9c0eebc506c56c64dc616cdf123fa671?d=identicon&s=25 Chris Chris (aboulafia)
on 2006-03-25 11:45
Fine - I didn't noticed the difference between destroy and delete, I
tought destroy was an alias to delete.

Thanks a lot !
This topic is locked and can not be replied to.