Skip to content

Instantly share code, notes, and snippets.

@anujbiyani
Created September 24, 2019 17:55
Show Gist options
  • Save anujbiyani/1b31a6d16397b476ed3f3eadaacf2a3a to your computer and use it in GitHub Desktop.
Save anujbiyani/1b31a6d16397b476ed3f3eadaacf2a3a to your computer and use it in GitHub Desktop.
Tricking PaperTrail into saving attributes that didn't change - solution
patient_preferences = create(
:patient_preferences,
health_information_exchange_opt_in: true,
health_information_exchange_legal_text_version: 1
)
patient_preferences.reload
# Add the following two lines
patient_preferences.health_information_exchange_opt_in_will_change!
patient_preferences.health_information_exchange_legal_text_version_will_change!
patient_preferences.health_information_exchange_opt_in = true
patient_preferences.health_information_exchange_legal_text_version = 2
puts patient_preferences.changes
#=> {"health_information_exchange_opt_in"=>[true, true], "health_information_exchange_legal_text_version"=>[1, 2]}
patient_preferences.save!
puts patient_preferences.versions.last.object_changes
#=> ---
#=> health_information_exchange_opt_in:
#=> - true
#=> - true
#=> health_information_exchange_legal_text_version:
#=> - 1
#=> - 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment