开发者

SEO friendly urls for mongo

开发者 https://www.devze.com 2023-03-17 12:56 出处:网络
I want to replace url posts/:id with posts/:title in mongo. Is there any way to do it. I tried using key in model

I want to replace url posts/:id with posts/:title in mongo. Is there any way to do it. I tried using key in model

class Post
  include Mongoid::Document
  include Mongoid::Timestamps

  field :title
  key :title
end

but my url does not change and also I am getting this error Document not found for class Post with id(s)

Am I missing st开发者_如何学Ch here?


Why are you using

field :key

The correct syntax should be rather key :field_name For further reference on how to use the key check out this link and scroll to the bottom

I doubt it would change the routes though.


If you are using Mongoid instead of the ActiveRecord you can use a gem called slugoid, slugoid

to generate pretty urls.

0

精彩评论

暂无评论...
验证码 换一张
取 消