Fruit flies are the staple pests in the kitchen during summer. As much as these unwelcomed guests enjoy feeding on fruit and other sugary substances, they are more attracted to the smell of rotting fruit than anything else.
The reason? Specific receptors on their olfactory neurons allow the flies sniff out a main product generated from fruit fermentation--acetic acid. With the presence of yeast and certain types of bacteria, glucose and other six carbon-based monosaccharides are turned into ethanol and then lactic acid, the main ingredient of vinegar. That's why one can trap more flies with vinegar than sugary water.
What's more interesting, scientists found that the intensity of the vinegar smell emit from rotting fruits need to be in a specific range. The fruit flies become indifferent if the concentration of lactic acid is too low or too high. The right amount of vinegar smell seems to be the indicator of a just-ripe fruit with maximum sugar content.
Source: ACS Reactions via Youtube