Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string_extensions.rb

Instance Method Summary collapse

Instance Method Details

#urlizeObject

Convert an arbitrary string into a format suitable for use in a URL

  • Replaces spaces with dashes

  • Converts to all lower-case

  • Removes all characters except alphabetic and numeric

  • Removes any trailing dashes (for ease in urlizing things like “#name-#optional_city”)



8
9
10
11
12
13
14
# File 'lib/string_extensions.rb', line 8

def urlize
  if ActiveSupport::Inflector.respond_to?(:parameterize)
    self.parameterize
  else
    self.gsub(" ","-").downcase.gsub(/[^a-z0-9-]/,"").gsub(/(-)*$/,"")
  end
end