Hi! In my view I’ve got a thing like this, that is a list with
checkboxes for visibility.
<% form_tag :action => ‘update_entries’ do%>
<% @entries.each do |e| -%>
<% @e=e -%>
<%= e.date -%>
<%= e.title -%>
<%= e.content -%>
<%= check_box( ‘e[]’,‘visible’,{},true,false) %>
<% end -%>
<%= submit_tag %>
<% end %>
When I send the form, this method is correctly executed:
def update_entries
Entry.update(params[:e].keys, params[:e].values);
redirect_to :action => ‘list’
end
Ok. But in Mongrel I see this:
Parameters: {“commit”=>“Save changes”, “action”=>“update_entries”,
“e”=>{“34”=>{“visible”=>“true”}, “35”=>{“visible”=>“false”},
“36”=>{“visible”=>“false”}, “37”=>{“visible”=>“false”},
“38”=>{“visible”=>“false”}, “39”=>{“visible”=>“false”}},
“controller”=>“admin”}
and then this one for each entry (even those I didn’t change):
Entry Load (0.001275) SELECT * FROM entries WHERE (entries.“id” = 34)
Entry Update (0.040439) UPDATE entries SET “visible” = ‘t’,
“content” = ‘test text’, “title” = ‘test title’, “entry_date” =
‘2007-10-15’ WHERE “id” = 34
So, I think that update is updating ALL the rows, and all the cols, not
only the rows/cols I’ve just changed. That’s not a good thing for me.
How can I fix this?
I’ve tried also this:
def update_entries
params[:e].each do |p|
row = Entry.find(p[0])
row.update_attribute(p[1].keys,p[1].keys)
end
redirect_to :action => ‘list’
end
I thought at least that update_attribute would write all the rows but
only in the ‘visible’ column, but it seems it does exactly the same
things of update, instead.
I really don’t understand why. Anyone can help me?