Skip to content

Instantly share code, notes, and snippets.

@mkmms
Created March 14, 2019 12:42
Show Gist options
  • Save mkmms/34f35044d8a89f283f5c51dc2571dde8 to your computer and use it in GitHub Desktop.
Save mkmms/34f35044d8a89f283f5c51dc2571dde8 to your computer and use it in GitHub Desktop.
#model
validates_uniqueness_of :slug
validates_presence_of :slug
before_save :check_slug
def check_slug
self.slug = self.slug.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment