Gem 推荐 mongoid 下的 friendly_id: mongoid-slug

lilu · October 08, 2012 · 4460 hits

mongoid-slug

已升级为 1.0.0,简便好用

class Book
  include Mongoid::Document
  include Mongoid::Slug

  field :title
  slug :title
end

于是 book resource 的 url 可以非常美好, "books/a-thousand-plateaus"

更难能可贵的是对中文支持不错,比如book.title="ruby指南"

产生的 url,“books/rubyzhi-nan"

这是基于字符串加强 gem stringex

如果拼音重复了,会在后面自动加序数,比如“books/rubyzhi-nan-1"

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.