'Can I get the time from the status change without adding additional column or using updated_at?
How to detect attribute changes from model? Relating to this question, can i see the time when the status is changed? please guide and help.
Solution 1:[1]
You can utilize rails Active Model Dirty to check if a particular column in the model changed.
For example, imagine a Car class with a column status that you would like to observe. As Rails auto-generates the method status_changed?, you can use this as a conditional check to execute your custom method and read the time.
class Car
before_update :my_custom_method, if: :status_changed?
def my_custom_method
# read the time
end
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
