Showing posts with label active-record. Show all posts
Showing posts with label active-record. Show all posts

Monday, January 14, 2013

The not so famous before_remove/before_add & after_remove/after_add callbacks.

Well, this is another rails feature and a quite nice one which is not documented properly.

While using has_many :through associations, we can use before_remove, before_add, after_remove, after_add callbacks.

Thursday, December 20, 2012

Rails 2.3 after_create callback doesn't rollback even if returned false

So, this is another mind-boggling thing i came across yesterday. I am working on rails 2.3.11

So i had some after_create callbacks on my app's Order model.

The problem i faced was even when the callbacks would fail, the order was still created and the changes would't ROLLBACK!!

Thursday, October 11, 2012

Get value of an attribute before being type-casted by rails

There are times when we might need the value of an attribute before rails type-casting it.

Suppose obj is the object and attrib is the attribute whose value we need before ActiveRecord type-casted it, there's a method we can use to get the value of that attribute it was before being type-casted, which works as follows: