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 the scents generated from fruit fermentation. The fermentation of sugars produces a volatile compound--lactic acid, the main ingredient of vinegar. With the presence of yeast or certain types of bacteria, glucose and other six carbon-based monosaccharides can ultimately be turned into lactic acid, as a source of food for the microbes. 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