In my rails model I need to call after_commit
callback if and only if one of the table attributes is changed from one value to other.
This is working fine with after_update
callback but I am invoking some additional tasks in the background and after_commit
is the perfect one for this. Any suggestions?
Sample code
after_commit :call_cli, :if=> :change
def change
if self.status_changed?
filename = '/location/res.log'
File.open(filename, File::WRONLY) do |file|
file.write self.status_change_was+"\n"
end
end
end