如何扩展/子类SearchLogic::Search?
这是我正在尝试的:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑到这里没有太多的搜索逻辑帮助,我决定不删除这个问题,而是自己回答。
模块名称为
Searchlogic
,带有小写的L
。这是正确的
app/models/product_search.rb
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 lowercaseL
.Here is the correct
app/models/product_search.rb