Created
August 19, 2008 19:25
-
-
Save jblanche/6223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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