Mongo ids leads to scary URLs

前端 未结 4 1244
时光取名叫无心
时光取名叫无心 2020-12-24 01:52

This might sound like a trivial question, but it is rather important for consumer facing apps

What is the easiest way and most scalable way to map the scary mongo id

4条回答
  •  -上瘾入骨i
    2020-12-24 02:15

    Here's a great gem that I've been using to successfully answer this problem: Mongoid-Slug

    https://github.com/digitalplaywright/mongoid-slug.

    It provides a nice interface for adding this feature across multiple models. If you'd rather roll your own, at least check out their implementation for some ideas. If you're going this route, look into the Stringex gem, https://github.com/rsl/stringex, and acts_as_url library within. That will help you get the nice dash-between-url slugs.

提交回复
热议问题