代码之家  ›  专栏  ›  技术社区  ›  maček

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

  •  0
  • maček  · 技术社区  · 14 年前

    应用程序/模型/产品.rb

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

    应用程序/型号/产品_搜索.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 回复  |  直到 14 年前
        1
  •  0
  •   maček    14 年前

    模块名为 Searchlogic 带小写字母 L .

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

    class ProductSearch < Searchlogic::Search
    
      include Searchlogic
    
      def foobar
        puts :custom_method
      end
    
    end
    
    推荐文章