Code:
<%= check_box_tag(“person[#{person.id}][is_approved]”, 1, true) %>
Rendered output:
Problem:
The value of “1” is always passed, even if the box is UNCHECKED.
Suggestions? Thanks!
Code:
<%= check_box_tag(“person[#{person.id}][is_approved]”, 1, true) %>
Rendered output:
Problem:
The value of “1” is always passed, even if the box is UNCHECKED.
Suggestions? Thanks!
Taylor S. wrote:
Code:
<%= check_box_tag(“person[#{person.id}][is_approved]”, 1, true) %>Rendered output:
Problem:
The value of “1” is always passed, even if the box is UNCHECKED.
Suggestions? Thanks!
http://www.ruby-forum.com/topic/60783
–
Michael W.
Michael W. wrote:
Taylor S. wrote:
Code:
<%= check_box_tag(“person[#{person.id}][is_approved]”, 1, true) %>Rendered output:
Problem:
The value of “1” is always passed, even if the box is UNCHECKED.
Suggestions? Thanks!
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]]”
:index fixed this. Hooray for undocumented features!
You’ll have to add your own hidden checkbox input then. There’s no other
way
around it really. Sometimes it helps to write your own helper for it
though.
One less thing to remember and it’s DRY.
RSL
For an array of users with boolean attributes here is how I iterated:
for person in @people
<%= check_box(‘person’, ‘is_approved’, options = {:index => person.id,
:checked => person.is_approved}, checked_value = “1”, unchecked_value =
“0”) %>
Cool.
RSL
:index fixed it? Care to explicate or should I just dig in the source?
[Hint, hint.]
RSL
Very cool. I’ve needed something like that before. Wish I’d known that
then!
–
Nathan Garza
AshLeaf Media | Director of Technology Innovations
www.ashleafmedia.com | [email protected] | 832.514.5726
Liana wrote:
Taylor S. wrote:
For an array of users with boolean attributes here is how I iterated:
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
Taylor S. wrote:
For an array of users with boolean attributes here is how I iterated:
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!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs