Skip to content

Instantly share code, notes, and snippets.

@odigity
Last active October 6, 2015 02:35
Show Gist options
  • Select an option

  • Save odigity/e33fd1b31fd26167a120 to your computer and use it in GitHub Desktop.

Select an option

Save odigity/e33fd1b31fd26167a120 to your computer and use it in GitHub Desktop.
class ModelBase
# depends on Dirty plugin: http://www.rubydoc.info/gems/sequel/Sequel/Plugins/Dirty
def validates_unchanged(attribute)
errors.add(attribute, 'cannot be modified') if !new? and column_changed?(attribute)
end
end
class Model < ModelBase
def validate
validates_unchanged :username
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment