开发者

SEO friendly urls for mongo

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜