dimanche 22 janvier 2017

Rails search according to multiple checkbox value

I'm troubled to search according to multiple checkbox values like I have a post table where persons post by locations:

Checkbox:

 #=> Form method get
<%= check_box_tag("post_location", "London") %>
<%= check_box_tag("post_location", "Azle") %>
<%= check_box_tag("post_location", "Azure") %>
<%= check_box_tag("post_location", "Arma") %>

Controller:

@posts= Post.where(["post_location LIKE ? ", "%#{params[:post_location]}%"]).where(["post_title LIKE ? ", "%#{params[:post_title]}%"])

But always show result based on the last checkbox.

How can show all results based on all checkbox values?

Thanks




Aucun commentaire:

Enregistrer un commentaire