Ruby syntax to loop through items, take a count, then act on the result ... not working -


i have ruby passing web control (dropdownlist). intent count number of listitems selected, , if count > 1, deselect first item in drop down list.

this have far .. doesn't break, count comes out 0, when force more items selected.

return control if control.nil?;  count = 0; control.items.each { |item| if item.selected == "true" count+=1 end } if count > 1   control.items[0].selected = "false" end return control; 

i have tried item.selected = 1 well, thinking being treated bit. can point out have messed up.

thanks

still using "string boolean":

unless control.nil?   if control.items.select { |item| item.selected == "true" }.count > 1     control.items[0].selected = "false"   end end  return control; 

using real boolean:

unless control.nil?   control.items[0].selected = false if (control.items.select { |item| item.selected }.count > 1) end  return control; 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -