2013-02-05 14:16:51 -05:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-03-06 02:52:24 -05:00
|
|
|
# Generates a slug. This is annoying because it's duplicating what the javascript
|
2013-02-05 14:16:51 -05:00
|
|
|
# does, but on the other hand slugs are never matched so it's okay if they differ
|
|
|
|
# a little.
|
|
|
|
module Slug
|
|
|
|
|
|
|
|
def self.for(string)
|
2013-05-30 11:54:02 -04:00
|
|
|
slug = string.parameterize.gsub("_", "-")
|
|
|
|
slug =~ /[^\d]/ ? slug : '' # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|