如何扩展/子类SearchLogic :: Search?

时间:2010-09-04 07:20:18

标签: ruby-on-rails searchlogic

以下是我正在尝试的内容:

应用程序/模型/ product.rb

class Product < ActiveRecord::Base
  class << self
    def searchlogic(conditions = {})
      ProductSearch.new(self, scope(:find), conditions)
    end
  end
end

应用程序/模型/ product_search.rb

require "searchlogic/search"

class ProductSearch < SearchLogic::Search

  include SearchLogic

  def foobar
    puts :hello_world
  end

end

测试

~/project $ script/console
>> @search = Product.searchlogic
  

NameError:未初始化的常量SearchLogic

SearchLogic::Search进行子类化或扩展的适当方法是什么?

1 个答案:

答案 0 :(得分:0)

考虑到SO的搜索逻辑帮助不多,我决定不删除这个问题,而是自己回答。

模块名称为Searchlogic,小写L

这是正确的app/models/product_search.rb

class ProductSearch < Searchlogic::Search

  include Searchlogic

  def foobar
    puts :custom_method
  end

end