为我的 application_controller 编写代码以将用户输入转换为查询,这是有效的:
result_set = model # some implementation of ActiveRecord::Base as a Class
.includes(:metric_template => [:group]) #still need to abstract this
.where(f)
.order(sort_string)
.limit(rows)
.offset((page-1)*rows)
这不起作用,因为似乎没有调用 where 方法:
result_set = model
.includes(:metric_template => [:group]) #still need to abstact this
.tap{|o| o.where(f) if f}
.order(sort_string)
.limit(rows)
.offset((page-1)*rows)
我真的很想 .tap() 在这里工作。为什么不呢?它不能作为类方法使用吗?可以说服吗?
感谢任何指导。