如何使对象路径 / url 与对象名称相关?
How can I make the object path / url relate to object name?
我有像
这样的对象
class Book
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :notes, type: String
end
我的 url 我的一个对象,当我展示它时就像 http://localhost:3000/coins/5a2e9e460d5fdd0a32153c31
如何使 url 与对象名称 (#{book.name}) 相关联,例如
http://localhost:3000/coins/harrypotter
或
http://localhost:3000/coins/mazerunner
或
http://localhost:3000/coins/coolbook
你应该使用 friendly_id gem 并且它非常简单
我有像
这样的对象class Book
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :notes, type: String
end
我的 url 我的一个对象,当我展示它时就像 http://localhost:3000/coins/5a2e9e460d5fdd0a32153c31
如何使 url 与对象名称 (#{book.name}) 相关联,例如
http://localhost:3000/coins/harrypotter
或
http://localhost:3000/coins/mazerunner
或
http://localhost:3000/coins/coolbook
你应该使用 friendly_id gem 并且它非常简单