Hi Doug,
I was hoping to give you a proof of concept when I read your post this
morning. Well, such are the plans, eh… Anyway, my thought was:
You could create hidden fields for all your checkboxes with initial
values. You may also need an instance variable array of these items,
then
in your action you could cycle through the array and get the name of the
checkbox and check its value in params.
Something like (please check the syntax on all code):
controller-action: index
session[:check_boxes] = [a, b, c]
view template: index
<% form, :action=>‘create’ %>
<%= check_box_tag, a, :value=>off %>
<%= hidden_field, a, :value=>off %>
<%= check_box_tag, b, :value=>off %>
<%= hidden_field, b, :value=>off %>
<%= check_box_tag, c, :value=>off %>
<%= hidden_field, c, :value=>off %>
<% end %>
controller-action: create
@check_boxes = session[:check_boxes]
@on = 0
@off = 0
@check_boxes.each do |cb|
end
As I aluded to above, this is not tested. Now, what I’m not sure of is
how
the interaction will work between hidden fields and check_box field with
identical names. There’s nothing wrong with it, you have the same thing
in
a radio-groups, for example. I’m just not sure which setting will ‘win
out’.
Hope it gets you started. (Feel free to reply to my gmail dot com
account
under the name dfdumaresq)
Regards,
Dave
Information and Educational Technology
Kwantlen University College - 604-599-2120
“So powerful is the light of unity that it can illuminate the whole
earth.” --Bahá'u’lláh
“doug” [email protected]
Sent by: [email protected]
19-03-2007 05:00 PM
Please respond to
[email protected]
To
“Ruby on Rails: Talk” [email protected]
cc
Subject
[Rails] check_box_tag
It ppears that the check_box_tag inserts a name/value
pair into params{} only when the checkbox is checked
and inserts nothing when the checkbox is unchecked.
This means that if one simply cycles through the keys
in params{}, the names of fields associated with
unchecked check boxes will be omitted. I was hoping
that there was a way to get name/value pairs for
unchecked check boxes with the value (presumably)
being set to something that would indicate the
unchecked condition. Any ideas on how I can work
around this problem? Thanks for any input.
... doug