# ActiveRecord callbacks not called

**URL:** <https://www.ruby-forum.com/t/activerecord-callbacks-not-called/56583>\
**Category:** Rails\
**Created:** [April 1, 2006, 10:59am UTC](https://www.ruby-forum.com/t/activerecord-callbacks-not-called/56583 "2006-04-01T10:59:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 1, 2006, 10:59am UTC](https://www.ruby-forum.com/t/activerecord-callbacks-not-called/56583/1 "2006-04-01T10:59:31Z")

</div>

Hi, there must be something wrong somewhere in my unit test because  
there’s a model I can’t have any callback executed on.

In my unit test I do  
@image = Image.new  
@image.set\_uploaded\_file({:file =\>  
uploaded\_file(“pic1.jpg”,“image/jpeg”,“article-picture.jpg”),  
:article\_id =\> @article.id,  
:title =\> ‘Titre test’  
})  
breakpoint  
assert @image.save

When breakpointing, and trying @image.save manually I get a “true” as a  
result. So I presume everything went fine.

The model is :  
class Image \< ActiveRecord::Base  
belongs\_to :article  
before\_destroy :on\_before\_destroy  
after\_save :on\_after\_save  
validates\_presence\_of :extension

#cutted code

def on\_after\_save  
breakpoint  
end

end

The breakpoint in on\_after\_save is never reached.

I’m pulling my hairs out since yesterday - Any idea ?

Thanks

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 2, 2006, 10:18am UTC](https://www.ruby-forum.com/t/activerecord-callbacks-not-called/56583/2 "2006-04-02T10:18:34Z")

</div>

I’m still having this problem, any idea ?

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 2, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/activerecord-callbacks-not-called/56583/3 "2006-04-02T18:26:13Z")

</div>

Nuno wrote:

> Hi, there must be something wrong somewhere in my unit test because  
> there’s a model I can’t have any callback executed on.
> 
> In my unit test I do  
> @image = Image.new  
> @image.set\_uploaded\_file({:file =\>  
> uploaded\_file(“pic1.jpg”,“image/jpeg”,“article-picture.jpg”),  
> :article\_id =\> @article.id,  
> :title =\> ‘Titre test’  
> })  
> breakpoint  
> assert @image.save
> 
> When breakpointing, and trying @image.save manually I get a “true” as a  
> result. So I presume everything went fine.
> 
> The model is :  
> class Image \< ActiveRecord::Base  
> belongs\_to :article  
> before\_destroy :on\_before\_destroy  
> after\_save :on\_after\_save  
> validates\_presence\_of :extension
> 
> #cutted code
> 
> def on\_after\_save  
> breakpoint  
> end
> 
> end
> 
> The breakpoint in on\_after\_save is never reached.
> 
> I’m pulling my hairs out since yesterday - Any idea ?

I think you just do it like this:

class Image \< ActiveRecord::Base  
belongs\_to :article  
validates\_presence\_of :extension

#cutted code

def after\_save  
breakpoint  
end

end

–Al Evans
