ruby rails check field changed

# 1. Add a boolean attribute to the model to track changes
class YourModel < ApplicationRecord
  attr_accessor :field_changed

  before_save :check_field_changed

  private

  # 2. Define a private method to check if the field has changed
  def check_field_changed
    self.field_changed = field_changed?(:your_field_name)
  end
end