Home>
Thing I want to do

I want to receive in multiple params and complete the search function.

Current code
    keywords = params [: city_id] [: keyword] .split (/ [[: blank:]] + /). select (&: present?)
      pagy, offices = pagy_array ([])
      keywords.each do | keywords |
        offices + = Office.where ('name LIKE (?) OR
                                 address LIKE (?) OR
                                 near_station LIKE (?) OR
                                 introduction LIKE (?) OR
                                 company LIKE (?)',
                                "% # {keyword}%",
                                "% # {keyword}%",
                                "% # {keyword}%",
                                "% # {keyword}%",
                                "% # {keyword}%"). where (city_id: params [: city_id])
      end

I want to display Office when city_id and keyword are entered at the same time and searched.

City_id is an exact match and can be selected multiple times.

The keyword can be multiple words. Fuzzy search. It is an OR search.

  • Answer # 1

    params [: city_id]&¶ms [: keyword]