# CallBacks

**URL:** <https://www.ruby-forum.com/t/callbacks/192130>\
**Category:** Rails\
**Created:** [July 24, 2010, 2:24pm UTC](https://www.ruby-forum.com/t/callbacks/192130 "2010-07-24T14:24:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hari\_bhat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/82dd89/32.png) [@hari\_bhat](https://www.ruby-forum.com/u/hari_bhat)\
**Post date:** [July 24, 2010, 2:24pm UTC](https://www.ruby-forum.com/t/callbacks/192130/1 "2010-07-24T14:24:49Z")

</div>

Hi

```
                     I want to know more about callbacks in

```

rails,i am not getting in application when have to use?.

I know it acts like triggers .Please explain me with examples.

Regards  
hari

---

<div class="post-metadata">

**Author:** ![hari\_bhat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/82dd89/32.png) [@hari\_bhat](https://www.ruby-forum.com/u/hari_bhat)\
**Post date:** [July 27, 2010, 3:43pm UTC](https://www.ruby-forum.com/t/callbacks/192130/2 "2010-07-27T15:43:21Z")

</div>

hari bhat wrote:

> ```
> I want to know more about callbacks in
> 
> ```
> 
> rails,i am not getting in application when have to use?.
> 
> I know it acts like triggers .Please explain me with examples.

I assume you are referring to the ActiveRecord callbacks like  
before\_save, after\_save, before\_validation, etc. Understanding them is  
pretty simple. They are basically “hooks” into the ActiveRecord call  
stack. These “hooks” are opportunities to inject your own code to be run  
by the Rails framework in a consistent and reliable way.

There are many scenarios that you will run across where these hooks are  
useful. For example you may want to format, or otherwise modify, user  
input before performing validation. Such code can be implemented in a  
before\_validation method. All that’s required is to implement the method  
in the associated model class. This method will be automatically called,  
at the appropriate time, by the Rails framework. This provides a clean,  
consistent API for performing such tasks.
