method
to_param
![Some documentation Importance_1](https://d2vfyqvduarcvs.cloudfront.net/images/importance_1.png?1349367920)
Register or
log in
to add new notes.
james -
July 22, 2008 - (v1.0.0 - v2.1.0)
![Default_avatar_30](https://www.gravatar.com/avatar/9338c9a8ebddbcd4035280e6d0d52c31?default=http://apidock.com/images/default_avatar_30.png&size=30)
4 thanks
Better slug generation (essentially a to_param replacement)
Monkey Patching String
class String def slugify returning self.downcase.gsub(/'/, '').gsub(/[^a-z0-9]+/, '-') do |slug| slug.chop! if slug.last == '-' end end end
In a model, or wherever
def to_param # Don't need the id here if we're looking up the model by the stored slug. "#{id} #{title}".slugify end