Rails3 after_commit

Posted: December 24, 2010 in Ruby On Rails, Uncategorized
Tags: , ,

Rails 3  after_commit callback:

In rails 3 after_commit gem’s all functionality is now natively available in its library. There is some syntax variation in Rails 2 and Rails 3 as follow

Syntax in Rails 3 :

# commit after every save
after_commit :my_method

# commit after on save record
after_commit :my_method : on => :create

# commit after on update record
after_commit :my_method : on => :update

# commit after on delete record
after_commit :my_method : on => :destroy

Syntax in Rails 2 :

# commit after every save
after_commit :my_method

# commit after on save record
after_commit_on_create :my_method

# commit after on update record
after_commit_on_update :my_method

# commit after on delete record
after_commit_on_destroy :my_method

 

So, for rails 3 now no need to install any gem or plugin of after_commit.

Good Luck ;)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s