Skip to content

Instantly share code, notes, and snippets.

@gerrywastaken
Created June 28, 2012 06:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gerrywastaken/3009444 to your computer and use it in GitHub Desktop.
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