Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ransack and checkboxes #53

Closed
suciuvlad opened this issue Dec 24, 2011 · 2 comments
Closed

ransack and checkboxes #53

suciuvlad opened this issue Dec 24, 2011 · 2 comments

Comments

@suciuvlad
Copy link

model CLINIC has many TREATMENTS

I'm doing an advanced search on the clinics to filter them. I have this in my form:
<%= check_box_tag "q[treatments_id_eq][]", treatment.id, {} %>

Basically, i'm trying to send an array of the selected treatments to the search. I get the following error:
undefined method `to_i' for ["1", "2"]:Array

Using treatments_id_eq_ANY works and this is the generated query:
SELECT DISTINCT "clinics".* FROM "clinics" LEFT OUTER JOIN "countries" ON "countries"."id" = "clinics"."country_id" LEFT OUTER JOIN "clinics_treatments" ON "clinics_treatments"."clinic_id" = "clinics"."id" LEFT OUTER JOIN "treatments" ON "treatments"."id" = "clinics_treatments"."treatment_id" WHERE (("treatments"."id" = 1 OR "treatments"."id" = 2))

However I want to have them connected by AND instead of OR (WHERE (("treatments"."id" = 1 OR "treatments"."id" = 2)))

@joxxoxo
Copy link

joxxoxo commented Feb 14, 2012

if I'm not mistaken, you need treatments_id_eq_ALL. but how it's possible to be (("treatments"."id" = 1 AND "treatments"."id" = 2)) ?!
may be treatments_id_in[] ?

@suciuvlad
Copy link
Author

Hi,

It's been a while since i posted this.
Using "treatments_id_eq_ALL" works! I cannot believe i missed that!

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants