Skip to content

Instantly share code, notes, and snippets.

@marr
Last active June 9, 2017 22:04
Show Gist options
  • Save marr/4114ae6eb1804ea0737c35612a1bfeab to your computer and use it in GitHub Desktop.
Save marr/4114ae6eb1804ea0737c35612a1bfeab to your computer and use it in GitHub Desktop.
class Slug < ActiveRecord::Base
before_validation :generate_slug
validates :slug, presence: true, uniqueness: true
private
def generate_slug
self.slug = self.value.parameterize
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment