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| -%>
<div class="rev_todo_box">
<%= check_box("to_toggle", t.id, {:checked => t.done},
TRUE,
FALSE) %>
<%= t.description %>
</div>
<% 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!
--
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
-~----------~----~----~----~------~----~------~--~---