Created
January 8, 2014 02:32
-
-
Save lsiden/8310790 to your computer and use it in GitHub Desktop.
Here's a way to make a relation immutable that doesn't break.
This file contains hidden or 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
# Prevent self.user from being changed | |
alias_method :old_user_assign, :user= | |
def user=(new_user) | |
if self.new_record? | |
old_user_assign new_user | |
else | |
logger.warn "Attempt to modify user of record, id=#{self.id} with user id=#{new_user.id}" | |
return false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment