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

发布于 2024-09-18 09:38:35 字数 684 浏览 7 评论 0原文

这是我正在尝试的:

app/models/product.rb

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

app/models/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 的适当方法是什么?

Here is what I'm trying:

app/models/product.rb

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

app/models/product_search.rb

require "searchlogic/search"

class ProductSearch < SearchLogic::Search

  include SearchLogic

  def foobar
    puts :hello_world
  end

end

test

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

NameError: uninitialized constant SearchLogic

What's the appropriate way to subclass or extend SearchLogic::Search?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠魁 2024-09-25 09:38:35

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

模块名称为 Searchlogic,带有小写的 L

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

class ProductSearch < Searchlogic::Search

  include Searchlogic

  def foobar
    puts :custom_method
  end

end

Considering there's not very much searchlogic help here on SO, I decided not to delete this question and instead answer it myself.

The Module name is Searchlogic with a lowercase L.

Here is the correct app/models/product_search.rb

class ProductSearch < Searchlogic::Search

  include Searchlogic

  def foobar
    puts :custom_method
  end

end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文