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

前端 未结 12 864
北荒
北荒 2020-11-30 18:05

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 n

12条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 18:49

    The main issue for my apps has been the apostrophes - rarely do you want the -s sitting out there on it's own.

    class String
    
      def to_slug
        self.gsub(/['`]/, "").parameterize
      end
    
    end
    

提交回复
热议问题