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 -%><br />
<%= e.title -%><br />
<%= e.content -%><br />
<%= check_box(
''e[]'',''visible'',{},true,false) %>
<br /><br />
<% 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? :)
--
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
-~----------~----~----~----~------~----~------~--~---
On 2 Nov 2007, at 16:38, Luca Reghellin wrote:> 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): >This is intentional: you get one parameter for every checkbox, even if you didn''t change that check box (there''s some behind the scenes stuff with a hidden field), which brings it inline with all the other input types. If you use check_box_tag you won''t get this> 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? >Either use check_box_tag, or maybe use a hidden field ''previous value'' so that your controller knows which parameters to ignore> > 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? :)That''s the just the way it is right now (for better or for worse). Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok, now it''s all a bit clearer. Thank you very much! Frederick Cheung wrote:> On 2 Nov 2007, at 16:38, Luca Reghellin wrote: >> 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): >> > This is intentional: you get one parameter for every checkbox, even if > you didn''t change that check box (there''s some behind the scenes stuff > with a hidden field), which brings it inline with all the other input > types. If you use check_box_tag you won''t get this > >> How can I fix this? >> > Either use check_box_tag, or maybe use a hidden field ''previous value'' > so that your controller knows which parameters to ignore >> >> 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? :) > That''s the just the way it is right now (for better or for worse). > > Fred-- 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 -~----------~----~----~----~------~----~------~--~---