Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make attributes as read only and add errors to the columns
[:first_name=, :last_name=].each do |current|
alias_attribute current, :read_only
end
protected
def read_only attribute
attribute_name = caller[0][/`([^=']*)='/, 1] # Matches after first ` until = or ' is reached.
error_message = "sorry #{attribute_name} is read-only"
self.errors.add(attribute_name, error_message)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.