Store multiple check_box of same attribute in "Search" class

How do I store the value of multiple checkboxes as a result of using
“check_box” helper in a “Search” class? A “Search” class is explained
here: http://railscasts.com/episodes/111-advanced-search-form. For
example, a user should be able to search for all “Gay” OR “Bisexual”
users by clicking both checkboxes. These are values of attribute
“orientation”. My own research shows that I should do something like
this:

Store Search[:orientations] in the database in “text”.
In the search form:

<% form_for @search do |f| %>
<%= f.check_box orientations[], {}, 0, nil %>Straight
<%= f.check_box orientations[], {}, 1, nil %>Gay
<%= f.check_box orientations[], {}, 2, nil %>Bisexual

Then in the Search model:
serialize :orientations
See http://railsforum.com/viewtopic.php?id=15176

Will this work? I have not implemented this but I would like to know
if this is the right direction. I already see one problem: How does
the search form remember the checkboxes that the user has checked?
Unlike the radio_button helper where if the current value of method is
tag_value the radio button will be checked, I don’t see where
check_box examines the current value of orientations[] from the
database.

Thanks.

Can some one help me with this question below? Thanks.

How do I store the value of multiple checkboxes as a result of using
“check_box” helper in a “Search” class? A “Search” class is explained
here: http://railscasts.com/episodes/111-advanced-search-form. For
example, a user should be able to search for all “Gay” OR “Bisexual”
users by clicking both checkboxes. These are values of attribute
“orientation”. My own research shows that I should do something like
this:

Store Search[:orientations] in the database in “text”.
In the search form:

<% form_for @search do |f| %>
<%= f.check_box orientations[], {}, 0, nil %>Straight
<%= f.check_box orientations[], {}, 1, nil %>Gay
<%= f.check_box orientations[], {}, 2, nil %>Bisexual

Then in the Search model:
serialize :orientations
See http://railsforum.com/viewtopic.php?id=15176

Will this work? I have not implemented this but I would like to know
if this is the right direction. I already see one problem: How does
the search form remember the checkboxes that the user has checked?
Unlike the radio_button helper where if the current value of method is
tag_value the radio button will be checked, I don’t see where
check_box examines the current value of orientations[] from the
database.

Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs