Formation of gels in the presence of metal ions