ActivateRecord 定义 可搜索对象
class Post < ActiveRecord::Base
searchable do
text :title, :body
text :comments do
comments.map { |comment| comment.body }
end
boolean :featured
integer :blog_id
integer :author_id
integer :category_ids, :multiple => true
double :average_rating
time :published_at
time :expired_at
string :sort_title do
title.downcase.gsub(/^(an?|the)/, '')
end
end
end
搜索
Post.search do
fulltext 'best pizza'
with :blog_id, 1
with(:published_at).less_than Time.now
order_by :published_at, :desc
paginate :page => 2, :per_page => 15
facet :category_ids, :author_id
end
小结
我这里没有列出 Rails 生成的那些常用 gem ,以上的都是一些我收集和常用的 gem 希望能对大家有用。
另外,如果您收藏了更好的 gem 希望能在本文留评,而且请注明 gem 的作用和 RubyGems 上的下载链接,给更多的Ruby的爱好者一个综合性的资源汇总,Thanks!