  We investigate the color-magnitude distribution in the rich cluster AC 118 at
z=0.31. The sample is selected by the photometric redshift technique, allowing
to study a wide range of properties of stellar populations, and is complete in
the K-band, allowing to study these properties up to a given galaxy mass. We
use galaxy templates based on population synthesis models to translate the
physical properties of the stellar populations - formation epoch, time-scale of
star formation, and metallicity - into observed magnitudes and colors. In this
way we show that a sharp luminosity-metallicity relation is inferred without
any assumption on the galaxy formation scenario (either monolithic or
hierarchical). Our data exclude significant differences in star formation
histories along the color-magnitude relation, and therefore confirm a pure
metallicity interpretation for its origin, with an early (z~5) formation epoch
for the bulk of stellar populations. The dispersion in the color-magnitude
diagram implies that fainter galaxies in our sample (K~18) ceased to form stars
as late as z~0.5, in agreement with the picture that these galaxies were
recently accreted into the cluster environment. The trend with redshift of the
total stellar mass shows that half of the luminous mass in AC 118 was already
formed at $z~2, but also that 20% of the stars formed at z<1.
