Code: <%= check_box_tag("person[#{person.id}][is_approved]", 1, true) %> 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/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Taylor Strait wrote:> Code: > <%= check_box_tag("person[#{person.id}][is_approved]", 1, true) %> > > 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!http://www.ruby-forum.com/topic/60783 -- Michael Wang --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Wang wrote:> Taylor Strait wrote: >> Code: >> <%= check_box_tag("person[#{person.id}][is_approved]", 1, true) %> >> >> 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! > > http://www.ruby-forum.com/topic/60783 >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]]" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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 On 3/30/07, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Michael Wang wrote: > > Taylor Strait wrote: > >> Code: > >> <%= check_box_tag("person[#{person.id}][is_approved]", 1, true) %> > >> > >> 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! > > > > http://www.ruby-forum.com/topic/60783 > > > > 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]]" > > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
:index fixed this. Hooray for undocumented features! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
:index fixed it? Care to explicate or should I just dig in the source? [Hint, hint.] :) RSL On 3/30/07, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > :index fixed this. Hooray for undocumented features! > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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") %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Cool. RSL On 3/30/07, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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") %> > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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 | nathan-8gggxoBvU1PsBN0MCq728g@public.gmane.org | 832.514.5726 On 3/30/07, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote:> > Cool. > > RSL > > On 3/30/07, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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") %> > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Taylor Strait 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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Liana wrote:> Taylor Strait 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---