How can I search for multiple params? I have checkboxes in my view, so if multiple checkboxes are selected, I would like all the params selected to be chosen. I can currently only get the search to work with one param with code below.
There is a has_many to has_many association between car model and colour_collection model.
Controller:
@cars = car.joins(:colour_collections).where("colour_collections.name = ?", params[:colour_collection])
logs show this if two colours selected (e.g. red and green) creating duplicates in the resulting querie:
(0.7ms) SELECT COUNT(*) FROM "colour_collections"
ColourCollection Load (0.5ms) SELECT "colour_collections".* FROM "colour_collections"
Car Load (2.5ms) SELECT "cars".* FROM "cars" INNER JOIN "car_colour_collections" ON "car_colour_collections"."car_id" = "cars"."id" INNER JOIN "colour_collections" ON "colour_collections"."id" = "car_colour_collections"."colour_collection_id" WHERE "colour_collections"."name" IN ('Subtle', 'Intermediate') ORDER BY "cars"."created_at" DESC
CarAttachment Load (0.5ms) SELECT "car_attachments".* FROM "car_attachments" WHERE "car_attachments"."car_id" = $1 ORDER BY "car_attachments"."id" ASC LIMIT $2 [["car_id", 21], ["LIMIT", 1]]
CACHE (0.0ms) SELECT "car_attachments".* FROM "car_attachments" WHERE "car_attachments"."car_id" = $1 ORDER BY "car_attachments"."id" ASC LIMIT $2 [["car_id", 21], ["LIMIT", 1]]
CarAttachment Load (0.5ms) SELECT "car_attachments".* FROM "car_attachments" WHERE "car_attachments"."car_id" = $1 ORDER BY "car_attachments"."id" ASC LIMIT $2 [["car_id", 20], ["LIMIT", 1]]
CACHE (0.0ms) SELECT "car_attachments".* FROM "car_attachments" WHERE "car_attachments"."car_id" = $1 ORDER BY "car_attachments"."id" ASC LIMIT $2 [["car_id", 20], ["LIMIT", 1]]