Updating multiple records from a hash

I’m trying to figure out how to update multiple records in one method
from a hash sent by a view, and unfortunately, i’m dead stuck.

Here’s what i’m sending:

<% form_tag :controller => ‘todoitems’, :action => ‘toggle_todo’, :id =>
@id do -%>
<% if @todoitems then @todoitems.each do |t| -%>


<%= check_box(“to_toggle”, t.id, {:checked => t.done}, TRUE,
FALSE) %>
<%= t.description %>

<% end -%>
<% end -%>
<%= submit_tag ‘Update’ %>
<% end %>

This is what gets sent:

Parameters: {“commit”=>“Update”, “to_toggle”=>{“6”=>“true”,
“7”=>“false”, “8”=>“false”, “9”=>“true”}, “action”=>“toggle_todo”,
“id”=>“8”, “controller”=>“todoitems”}

And this is the controller def that should modify the records for me,
but it doesn’t do anything. I commented it out so people can see what
I’m trying to do:

def toggle_todo
#takes the hash out of params and assigns it to @toggle
@toggle = params[:to_toggle]
if @toggle
#iterate over the hash
@toggle.each do |id, value|
#find the record
@todoitem = Todoitem.find_by_id(id)
#change the record’s “done” column to the right value
@todoitem.done = value
end
end
#redirect
redirect_to :controller => ‘showproject’, :action => ‘show’, :id =>
params[:id]
end

Each todoitem has a “done” column that’s a boolean to show if it’s done
or not.

Anybody see what I’m missing? Thanks!

Ignore this thread. The server burped when I was submitting it, and I
ended up sending it twice. Sorry!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs