Created: 2008-05-23 17:06
Updated: 2018-08-27 08:24


Slugalizer is a one-method Ruby library that can slugalize (or slugify) strings, like this:

Slugalizer.slugalize("Åh, räksmörgåsar!")
# => "ah-raksmorgasar"

Defaults to the "-" word separator but can also use "+" or "_":

Slugalizer.slugalize("Åh, räksmörgåsar!", "+")
# => "ah+raksmorgasar"

Slugalizer.slugalize("Åh, räksmörgåsar!", "_")
# => "ah_raksmorgasar"

Uses ActiveSupport::Multibyte (part of Ruby on Rails since 1.2) for platform-consistent normalization/decomposition, since iconv from the Ruby standard library is inconsistent between platforms.

This library has been incorporated into Ruby on Rails (as ActiveSupport::Inflector#parameterize and String#parameterize) since 2008-09-23 (Rails 2.2). The library is still of use outside Rails, or with earlier Rails versions. It also has more extensive tests than the code in Rails, and some additional error handling (limited set of word separators, handling non-string input).

Originally by Christoffer Sawicki.

Modified by Henrik Nyh.

Released into the public domain.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more