#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> --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On 9/15/07, Ryan Angilly <angilly-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > #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> > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:> |#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> > | > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. Thanks On 9/15/07, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> > 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: > > #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> > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---