Skip to content

Instantly share code, notes, and snippets.

@quezo
Created February 22, 2012 04:29
Show Gist options
  • Save quezo/1881382 to your computer and use it in GitHub Desktop.
Save quezo/1881382 to your computer and use it in GitHub Desktop.
def make_safe_url(slug)
slug = slug.downcase
# strip html
slug = slug.gsub(/<\/?[^>]*>/, "")
# remove html entities
slug = slug.gsub(/[^;\s]+;/, "")
# remove non-word chars
slug = slug.gsub(/[^\w\s]/, "")
# change spaces to dashses
slug = slug.gsub(/\s+/, "-")
slug
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment