将参数传递给 searchlogic 中的scope_procedure
我想像这样使用 searchlogic 的 scope_procedure
功能
class MyModelObject < ActiveRecord::Base
scope_procedure :my_scope_proc, lambda { |p1, p2| { :conditions => "p1 >= #{p1} AND p2 < #{p2}" }}
end
然后,我正在进行搜索:
scope = MyModelObject.search(:my_scope_proc => true)
scope.all
上面的代码显然不起作用,因为我没有通过 p1
和 < code>p2 参数到我的命名范围。
我不知道如何将参数传递到命名范围。
I'd like to use searchlogic's scope_procedure
feature like so
class MyModelObject < ActiveRecord::Base
scope_procedure :my_scope_proc, lambda { |p1, p2| { :conditions => "p1 >= #{p1} AND p2 < #{p2}" }}
end
Then, I am doing the search:
scope = MyModelObject.search(:my_scope_proc => true)
scope.all
The above code obviously doesn't work because I didn't pass p1
and p2
parameters to my named scope.
I can't figure out how to pass parameters to the named scope.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个疯狂的猜测是(意思是,我没有检查!):
对scope_procedure的一个建议:
这可以防止SQL注入。
或者搜索逻辑方式:
A wild guess is (meaning, I didn't check!):
One suggestion for the scope_procedure:
This prevents SQL injection.
Or the searchlogic way:
我能够使用一个参数来使其工作,如下所示:
I was able to make it work with one parameter as follows: