I have a simple relationship:
User belongs_to Domain
User has a property email_address which I want to update if Domain is
I tried in User
but now the ability to assign new domains is totally broken and no
longer works (simply nothing happens)...
I suspect that this needs some magic reflection hacking, but can someone
set me on the right path to figure out how to work around it. Basically
I want to just intercept the update call and run some custom code to
update the User model.
Grateful for some ideas
Yes, you can't use super because AR defines the domain= method on
the User class itself.
self.email_address = blah(new_domain)
self.domain_without_email_update = new_domain
alias_method_chain :domain=, :email_update
Now user.domain = ... will also do an email update, but you can
use user.domain_without_email_update = ... for cases where you
don't want the email address updated.
We develop, watch us RoR, in numbers too big to ignore.