-2

I need to do some task before I destroy a user. I am doing a system for a network marketing company. I need to change the user of users. So this is what I did:

class User < ActiveRecord::Base


    def delete_this_user
      some_actions
.
.
.
      self.destroy
end


end

the

self.destroy doesn't destroy the user from the database. Can anybody help? Thanks

Peak Sornpaisarn
  • 885
  • 1
  • 9
  • 18

1 Answers1

2
class User < ActiveRecord::Base
  def delete_this_user
    some_actions
    self.class.delete(id)
  end
end

UPD (thx @Rich):

delete will skip all callbacks, whereas destroy will trigger every associated callback.

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145