before the loop:
Group.update_all(invitable_type: 'Group')

then inside the loop.. do
i.update_attribute(:invitable_id, i.group_id)

and lose the i.save line 

(note the capital G)