Skip to content

Instantly share code, notes, and snippets.

@lsiden
Created January 8, 2014 02:32
Show Gist options
  • Save lsiden/8310790 to your computer and use it in GitHub Desktop.
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.
# 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