Created
March 20, 2012 12:52
-
-
Save nuwansh/2135014 to your computer and use it in GitHub Desktop.
Takes the slug, downcases it and replaces non-word characters with a -
This file contains hidden or 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
# Takes the slug, downcases it and replaces non-word characters with a -. | |
# Feel free to override this method if you'd like different slug formatting. | |
def normalize_slug_url | |
return if self.name.blank? | |
s = ActiveSupport::Multibyte.proxy_class.new(self.name).normalize(:kc) | |
s.downcase! | |
s.strip! | |
s.gsub!(/[^a-z0-9\s-]/, '') # Remove non-word characters | |
s.gsub!(/\s+/, '-') # Convert whitespaces to dashes | |
s.gsub!(/-\z/, '') # Remove trailing dashes | |
s.gsub!(/-+/, '-') # get rid of double-dashes | |
self.url = s.to_s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment