CallBacks

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

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.