method
parameterize
parameterize(string, separator: "-", preserve_case: false, locale: nil)
public
Replaces special characters in a string so that it may be used as part of a ‘pretty’ URL.
parameterize("Donald E. Knuth") # => "donald-e-knuth" parameterize("^très|Jolie-- ") # => "tres-jolie"
To use a custom separator, override the separator argument.
parameterize("Donald E. Knuth", separator: '_') # => "donald_e_knuth" parameterize("^très|Jolie__ ", separator: '_') # => "tres_jolie"
To preserve the case of the characters in a string, use the preserve_case argument.
parameterize("Donald E. Knuth", preserve_case: true) # => "Donald-E-Knuth" parameterize("^très|Jolie-- ", preserve_case: true) # => "tres-Jolie"
It preserves dashes and underscores unless they are used as separators:
parameterize("^très|Jolie__ ") # => "tres-jolie__" parameterize("^très|Jolie-- ", separator: "_") # => "tres_jolie--" parameterize("^très_Jolie-- ", separator: ".") # => "tres_jolie--"
If the optional parameter locale is specified, the word will be parameterized as a word of that language. By default, this parameter is set to nil and it will use the configured <tt>I18n.locale.