How to filter results by multiple fields?
Posted
by hadees
on Stack Overflow
See other posts from Stack Overflow
or by hadees
Published on 2010-05-12T02:10:55Z
Indexed on
2010/05/12
2:14 UTC
Read the original article
Hit count: 300
I am working on a survey application in ruby on rails and on the results page I want to let users filter the answers by a bunch of demographic questions I asked at the start of the survey.
For example I asked users what their gender and career was. So I was thinking of having dropdowns for gender and career. Both dropdowns would default to all but if a user selected female and marketer then my results page would so only answers from female marketers.
I think the right way of doing this is to use named_scopes where I have a named_scope for every one of my demographic questions, in this example gender and career, which would take in a sanitized value from the dropdown to use at the conditional but i'm unsure on how to dynamically create the named_scope chain since I have like 5 demographic questions and presumably some of them are going to be set to all.
© Stack Overflow or respective owner