Last part of my project, Hopefully.
Need to check if user.email attribute changes. If it does, then need to tell mailchimp to change or add the email.
Looks like Dirty will do this, but have never used it before. How can I catch the change in a block, or pass it to a block, and then update the attribute?
Using the ActiveRecord::Dirty module is pretty straightforward:
bob = User.find_by_email('[email protected]')
bob.changed? # => false
bob.email = '[email protected]')
bob.changed? # => true
bob.email_changed? # => true
bob.email_was # => '[email protected]'
bob.email_change # => ['[email protected]', '[email protected]']
bob.changed # => ['email']
bob.changes # => { 'email' => ['[email protected]', '[email protected]'] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With