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.
精彩评论