简体   繁体   English

searchlogic-数组错误

[英]searchlogic - array error

I have the following controller method 我有以下控制器方法

def app_used_by_Lab
    per_id = params[:id]

    @search1 = Apparatus.used_by_specific_lab(per_id).search(params[:search]) # both 'used_by_specific_lab' & 'lab_created' are named_scopes which return results from the same table
    @search2 = Apparatus.lab_created(per_id).search(params[:search])
    @search = @search2 + @search1
    @search.order ||= :descend_by_RPR_DATE_CREATED
    @apparatuses = @search.paginate(:page => params[:page], :per_page => 10)
end

If I change the code to '@search = @search1' , it works fine and return me the results but when I do '@search = @search2 + @search1' , I get the error message below: 如果将代码更改为'@search = @search1' ,它可以正常工作并返回结果,但是当我执行'@search = @search2 + @search1' ,出现以下错误消息:

TypeError in ApparatusesController#app_used_by_Lab

can't convert Searchlogic::Search into Array

Is it not possible to use searchlogic on arrays? 不能在数组上使用searchlogic吗?

Is there any solution to the above problem? 以上问题有解决方案吗?

Thanks a lot for your precious help. 非常感谢您的宝贵帮助。

请尝试以下方法:

@search = @search2.to_s + @search1.to_s

尝试这个:

@search =  @search2.concat(@search1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM