Created
September 24, 2019 17:55
-
-
Save anujbiyani/1b31a6d16397b476ed3f3eadaacf2a3a to your computer and use it in GitHub Desktop.
Tricking PaperTrail into saving attributes that didn't change - solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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