Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Active Record: 'attribute_before_last_save' vs 'attribute_was'

So I was debugging a issue I was facing and I was struggling to understand why attribute_before_last_save works differently than attribute_was since in docs all I could get is that attribute_before_last_save behaves similarly to attribute_was but in my case I'm getting nil for one and correct value for another.

like image 694
Abhinav Srivastava Avatar asked Dec 24 '22 10:12

Abhinav Srivastava


1 Answers

attibute_before_last_save only work after you save data to db successful.

if you have a callback before save, you should use attibute_was.

like image 74
Michael Avatar answered Jan 04 '23 23:01

Michael