#check_box and #check_box_tag are going to be the end of me. Why is this always checked? <% checked = @reservation.selected ? 'checked' : nil %> <td><%= check_box_tag("reservation[" + @ reservation.id.to_s + "][selected]", 'checked', :checked => checked) %></td>
I figured it out
<% checked = (@reservation.selected == 'checked') ? 'checked' : nil %> <td><%= check_box_tag("reservation[" + @reservation.id.to_s + "][selected]", 'checked', checked) %></td>
@reservation.selected being 0 or ‘checked’ still returns true, which sets checked to ‘checked’ no matter what
Well, first, you don’t need the :checked => checked. Whether it is checked or not is determined by the third argument being true or false.
This will be named “check_box”, will have id “check_box”, a value of 1, and will be checked:
check_box_tag(:checked_box, 1, true)
This is the same as above, but won’t be checked
check_box_tag(:checked_box, 1, false)
Does this help?
Ryan Angilly wrote:
Yeah I was confused because I had looked at the source for the method, and I knew what you just said, but checked was evaluating improperly. Which made me think I misunderstood the method source. So I went looking around and found examples talking about using “:checked => …” and screwed me up even further.