Re: [Rails] Updating objects in arrays
On Mon, Nov 12, 2012 at 1:42 PM, byrnejb <byrnejb@harte-lyne.ca> wrote:
> I have an array of 10 ActiveRecord objects. I wish to iterate over the
> array and update an attribute. When I do this the underlying table row
> changes but the object in the array frequently does not. For example:
>
> count = 0
> current_entries.each do |entry|
> puts( entry.object_id )
> puts( current_entries[count].object_id )
> puts( "***" )
> puts( entry.lock_version )
> entry = set_customs_entry_status_for( entry, status )
You need to reload the object after updating it if you need to use the
updated version.
set_customs_entry_status_for( entry, status )
entry.reload
--
Greg Donald
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home