Topic: updating rows using check box

Hello. Have a good day. Here is my problem. I create the checkbox button where user can label their messages as read or unread. ( yes or no )

here is my view for

read.rhtml

New Message(s)
<%@newmessages.each do |newmessage| %><%= start_form_tag :action => 'readupdate', :id => newmessage.id%>
from : <%= link_to newmessage.from, :action => "user", :id => newmessage.from %>
at : <%= newmessage.date.strftime("%a %b %d %H:%M: %Y") %></br>
message : <%= newmessage.content %> <%= link_to "(delete)",
                    {:action => "delete_message", :id => newmessage.id},
                    :confirm => "Really delete ?" %>
    <input type="checkbox" id="message_dibaca" name="message[dibaca]" value="yes" />
</br>

<%end%>
<input class="submit_button" type="submit" name="submit" value="Submit"></td>
<%= end_form_tag %>

in my controller :-

def readupdate
id = params[:id]
if id && message = Message.find(id)
begin
message.update_attributes(params[:message])
end
end
end

So if I checked the check box "yes" it will update the colum in dibaca as yes. or else.

i try to use the checkbox but it will only update one by one when i click the submit button. I try to googling myself looking how to update all rows for selected checkbox yes but couldnt find any answer.

How can i update all rows in dibaca when i checked the checkbox as "yes" ?

any help ?

thanks.

Re: updating rows using check box

well I dont think that you can do it all in one shot. you'll need a loop of some kind in a method.

code from depot application in "Agil Web Development with Rails book"

  def do_shipping(things_to_ship)
    count = 0
    things_to_ship.each do |order_id, do_it|
      if do_it == "yes"
        order = Order.find(order_id)
        order.mark_as_shipped
        order.save
        count += 1
      end
    end
    count
  end

this code goes through each order one by one and marks them as shipped.

--