ID + Slug name in URL in Rails (like in StackOverflow)

前端 未结 6 1974
逝去的感伤
逝去的感伤 2020-12-28 08:29

I\'m trying to achieve URLs like this in Rails:

http://localhost/posts/1234/post-slug-name

with both ID and slug name instead of either

6条回答
  •  被撕碎了的回忆
    2020-12-28 09:26

    Use friendly_id. It has one nice feature: you can update your url without breaking the old one.

    Generating view url isn't working for me. I just added a small method in the model

    def to_param
      self.friendly_id
    end
    

提交回复
热议问题