Be careful updating Rails' ActiveRecord Model attributes in-place
I just spent a couple minutes debugging a simple method that was updating a string in my database.
The column in the database was initialized to empty string. I had a method which would pull that record from the database, reinitialize the value to empty string, and then append to it using the << operator. However, after calling save!, the record was not updated. This had me grumbling, "Why isn't ActiveRecord updating my attribute!"
It was due to my misunderstanding of how the ActiveRecord Dirty flag works in cases of in place attribute updating.
Below is an example that shows how this works and the use of the <attribute_name>_will_change! method:
For more info, checkout: