On Sat, Jul 4, 2009 at 2:35 PM, JannaB
<mistressjanna-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:
>
> I must be missing something. I have a list of values returned
(id''s to
> my ''associates'' table) and I want to update all of those
in the list.
> Presently, I iterate through the list, updating each one (see below).
>
> Isn;t there a way I can do this all in one fell swoopy in RoR, without
> having to iterate through the list? -Janna B.
>
> params[:form__list1].each do |id|
> associate = Associate.find(id)
> associate.update_attributes({:channel_id =>
> @channel.id, :joined_channel_datetime => DateTime.now})
> end
option 1: try using update_all
Note: Please see API documentation for further explaination.
option 2: rework the original code to eliminate the find call within the
block and iterate over the Association instances
associates = Associate.find( params[:form__list1] )
associates.each do | associate |
associate.update_attributes( {:channel_id => @channel.id,
:joined_channel_datetime => DateTime.now } )
end
Good luck,
-Conrad
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---