Send this to a friend
http://apidock.com/rails/Object/to_paramhttp://apidock.com/rails/Object/to_param#47-Better-slug-generation-essentially-a-to-param-replacement-
1
2 class String
3 def slugify
4 returning self.downcase.gsub(/'/, '').gsub(/[^a-z0-9]+/, '-') do |slug|
5 slug.chop! if slug.last == '-'
6 end
7 end
8 end
9
10
11
12
13 def to_param
14 "#{id} #{title}".slugify
15 end
class String
def slugify
returning self.downcase.gsub(/'/, '').gsub(/[^a-z0-9]+/, '-') do |slug|
slug.chop! if slug.last == '-'
end
end
end
def to_param
"#{id} #{title}".slugify
end