Skip to content

Instantly share code, notes, and snippets.

@jblanche
Created August 19, 2008 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jblanche/6223 to your computer and use it in GitHub Desktop.
Save jblanche/6223 to your computer and use it in GitHub Desktop.
#Small method in order to create an URL from a string
#Support accents (replace them by the same character without accent)
class String
def urlize(separator = '_')
url = ActiveSupport::Multibyte::Handlers::UTF8Handler.normalize(self,:d).split(//u).reject { |e| e.length > 1 }.join #replace accents
url.gsub(/[^[:alnum:]\-\s\_]/, '').split(/[\s\-\_]+/).delete_if{|i| i.empty?}.join(separator).downcase # urlize seriph GITHUB version
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment