Rendered output:
<input checked="checked" id="person[7][is_approved]"
name="person[7][is_approved]" value="1" type="checkbox">
Problem:
The value of "1" is always passed, even if the box is UNCHECKED.
Suggestions? Thanks!
--
Posted via http://www.ruby-forum.com/.
http://www.ruby-forum.com/topic/60783
--
Michael Wang
The reason I cannot use "check_box" is that I am passing an array of
values and check_box messes up the names: name="person[7][is_approved]"
becomes name="person[[7][is_approved]]"
for person in @people
<%= check_box('person', 'is_approved', options = {:index => person.id,
:checked => person.is_approved}, checked_value = "1", unchecked_value =
"0") %>
Hrm. I've got multiple rows each with a checkbox on my page. I need to
know for which rows the user checks the box.
I got this to work:
check_box_tag('person[][is_approved]', person.is_approved)
But ran into the "unchecked" problem. So I was excited to find this
thread... but when I tried this:
<%= check_box('person', 'is_approved', options = {:index => person.id,
:checked => person.is_approved}, checked_value = "1", unchecked_value =
"0") %>
I got the error below:
"Conflicting types for parameter containers. Expected an instance of
Array, but found an instance of Hash. This can be caused by passing
Array and Hash based paramters qs[]=value&qs[key]=value."
So, I tried this:
<%= check_box('person[]', 'is_approved', options = {:index => person.id,
:checked => person.is_approved}, checked_value = "1", unchecked_value =
"0") %>
And now I get this error:
"object[] naming but object param and @object var don't exist or don't
respond to id_before_type_cast"
Any ideas?
Thanks!
Okay, just for anyone who's interested. I got this to work by using
check_box_tag and the hidden field.
<%= people.each do |person| %>
<%= check_box_tag('person[][is_approved]', 1, 0)%>
<%= hidden_field_tag 'person[][is_approved]', 0 %>
<%= end %>
What was interesting about this is that you NEED to put the
hidden_field_tag BELOW the check_box_tag or else the values got out of
synch. In other words, I would check row #5 but when I submit the page,
it was row #6 that had the check mark.
Cheers!
Liana