Vincent P
2010-Feb-09 17:13 UTC
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.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Vincent P
2010-Feb-13 01:53 UTC
Re: Store multiple check_box of same attribute in "Search" class
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.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.