Ruby

Get slug of a object name

This code on a class definition get a slug from the name variable.

def slug
  @name = self.name.downcase.dup
  @name.gsub! ' ', '-'
  @name.gsub! 'á', 'a'
  @name.gsub! 'é', 'e' 
  @name.gsub! 'í', 'i'
  @name.gsub! 'ó', 'o'
  @name.gsub! 'ú', 'u'
  @name.gsub! 'ñ', 'n'
end

/* on view */

<%= category.name %> --> "Category Name"

<%= category.slug %> --> "category-name"