mardi 29 mars 2016

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

How to search based on all locations. Locations are stored in cookie , i want to search and get result like this, list properties in locations Delhi NCR or Mumbai or Pune or Hyderabad or Bangalore or Chennai or Coimbatore or Cochin

i written active record like this

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

so that i got sql query like this SELECT * FROMpropertiesWHERE (location LIKE '%Delhi NCR,Mumbai,Pune,Hyderabad,Bangalore,Chennai,Coimbatore,Cochin%')

seperated by comma, and also not getting search result if any location name is present in table. how to search according to all locations and list if any present?

Aucun commentaire:

Enregistrer un commentaire