Best way to generate slugs (human-readable IDs) in Rails

Tom Lehman picture Tom Lehman · Aug 19, 2009 · Viewed 50.1k times · Source

You know, like myblog.com/posts/donald-e-knuth.

Should I do this with the built in parameterize method?

What about a plugin? I could imagine a plugin being nice for handling duplicate slugs, etc. Here are some popular Github plugins -- does anyone have any experience with them?

  1. http://github.com/rsl/stringex/tree/master
  2. http://github.com/norman/friendly_id/tree/master

Basically it seems like slugs are a totally solved problem, and I don't to reinvent the wheel.

Answer

grosser picture grosser · Oct 14, 2011

In Rails you can use #parameterize

For example:

> "Foo bar`s".parameterize 
=> "foo-bar-s"