简体   繁体   中英

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:

TypeError in ApparatusesController#app_used_by_Lab

can't convert Searchlogic::Search into Array

Is it not possible to use searchlogic on arrays?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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