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.
Chris C. (Guest)
on 2006-03-24 16: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
Chris H. (Guest)
on 2006-03-24 19: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
Chris C. (Guest)
on 2006-03-25 12: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.