编写活动记录以根据 table 字段中的所有值进行搜索

Writing Active record to search based on all values in a table field

我想根据所有位置进行搜索,我将位置存储为 cookie。 我想搜索并获得这样的结果,在位置 Delhi NCR or Mumbai or Pune or Hyderabad or Bangalore or Chennai or Coimbatore or Cochin

中列出属性

我写过这样的活跃记录:

@location = cookies[:location_id] (here iam getting all locations)
@properties=Property.where("location LIKE ?", "%#{@location}%")

所以,我得到了 sql 这样的查询:

SELECT * FROM `properties` WHERE (location LIKE '%Delhi NCR,Mumbai,Pune,Hyderabad,Bangalore,Chennai,Coimbatore,Cochin%')` 

以逗号分隔,如果 table 中存在任何位置名称,也不会获得搜索结果。 如何根据所有位置搜索并列出是否存在?

请帮忙。 感谢任何帮助table

@location = cookies[:location_id]
@properties=Property.where("location IN (?)", @location.split(","))

试试这个