# ActiveRecord callbacks not happening

**URL:** <https://www.ruby-forum.com/t/activerecord-callbacks-not-happening/90383>\
**Category:** Rails\
**Created:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/activerecord-callbacks-not-happening/90383 "2006-01-05T17:44:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cooldudevamsee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f8ce5/32.png) [@cooldudevamsee](https://www.ruby-forum.com/u/cooldudevamsee)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/activerecord-callbacks-not-happening/90383/1 "2006-01-05T17:44:15Z")

</div>

Hi,

I have a model class like so:

class Candidate \< ActiveRecord::Base  
validates\_presence\_of :name  
@@index = FerretConfig::INDEX

def self.after\_destroy  
puts “Ferret: after\_destroy called”  
@@index.query\_delete("+id:#{self.id}  
+ferret\_class:#{self.class.name}")  
optimize\_index  
end  
end

But when I delete a record, the after\_destroy is never called. Nothing  
shown on logs from the puts statement. Am I missing something?

Thanks,  
Vamsee.

---

<div class="post-metadata">

**Author:** ![cooldudevamsee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f8ce5/32.png) [@cooldudevamsee](https://www.ruby-forum.com/u/cooldudevamsee)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/activerecord-callbacks-not-happening/90383/2 "2006-01-05T17:44:49Z")

</div>

I don’t think after\_destroy should be a class method. Try changing it  
to

def after\_destroy  
…  
end

One thing to watch out for is the ferret\_class will be tokenized when  
using query\_delete. So, ‘Candidate’ will become ‘candidate’. You  
might want to try creating a Boolean query with a TermQuery in it for  
the ferret class.

Here is the query I use:

bq = Search::BooleanQuery.new  
class\_term = Ferret::Index::Term.new(‘ferret\_class’, self.class.name)  
bq.add\_query(Ferret::Search::TermQuery.new(class\_term),  
Search::BooleanClause::Occur::MUST)  
id\_term = Index::Term.new(‘id’, self.id.to\_s)  
bq.add\_query(Search::TermQuery.new(id\_term),  
Search::BooleanClause::Occur::MUST)

I hope that helps.

-Lee

---

<div class="post-metadata">

**Author:** ![cooldudevamsee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f8ce5/32.png) [@cooldudevamsee](https://www.ruby-forum.com/u/cooldudevamsee)\
**Post date:** [January 6, 2006, 7:28am UTC](https://www.ruby-forum.com/t/activerecord-callbacks-not-happening/90383/3 "2006-01-06T07:28:30Z")

</div>

Lee M. wrote:

> I don’t think after\_destroy should be a class method.

Thanks Lee, changing it to an instance method did the trick.

Vamsee.
