Multiple models in one form concurrency problem

I’m using the Advanced Rails recipe ‘Handle multiple models in one
form’ and everything works as expected until I start concurrency
testing.

For example I have a Task model and a Server model where a task can
have multiple servers. Now if user1 and user2 edit task 100 at the
same time, user1 adds a new server to the task and saves, everything
is as it should be, however, user2 now simply changes something in the
task and saves and now the task has lost the extra server user1 added.

I’m currently using ROR 2.3.2 and I’ve got optimistic locking on both
models.

my code for saving eixisting servers is

def existing_server_attributes=(server_attributes)
servers.reject(&:new_record?).each do |server|
attributes = server_attributes[server.id.to_s]
if attributes
server.attributes = attributes
else
servers.delete(server)
end
end
end

So the code works exactly as its supposed to. It gets all the servers
for a task, compares that to the passed in set of existing servers and
deletes any servers that aren’t in the list of existing servers.
Except that its now deleting the newly created server that user1
added. Is there a neat solution to this as for the moment I can’t
think of one, or is it a case of going back to the original Bates
recipe and marking the server as deleted with a virtual attribute and
only deleting those servers? Should the servers.reject stop this
problem but it isn’t working for some reason? Any help is much
appreciated. Thanks.