The melon fly, Bactrocera cucurbitae (Coquillett), is an invasive pest of fruits and vegetables and. Melon fly attractants have been used in control strategies to reduce pest levels and have gained widespread attention in recent years. Previous studies have shown that some host fruits are attractive to melon flies; however, few have investigated the chemical compounds responsible for their attraction. In this study, volatile compounds from Luffa acutangula L. were isolated and identified using dynamic headspace adsorption and gas chromatography-mass spectrometry (GC-MS), and their effects on B. cucurbitae were investigated using electroantennography (EAG) and behavioral tests (trap assays). Chemical profiling identified 21 compounds in ridge gourds, with stearyl alcohol, methyl myristate, phenyl acetate, and methyl stearate being the major components. The EAG results revealed that 12 compounds elicited antennal responses in B. cucurbitae, and the differences in antennal responses between male and female B. cucurbitae adults caused by heptanal, phenyl acetate, p-xylene, alpha-pinene, and 1-octadecene were significant. Moreover, in the behavioral experiment, the EAG-active compounds methyl isovalerate, methyl myristate, 1-octadecene, methyl laurate,heptanal, and 1-decanol had either attractive or repellent effects on B. cucurbitae. Our findings provide a theoretical basis producing repellents or attractants for effective green control of B. cucurbitae.