Rainbow effect in illustrator

Hi,

could someone explain how to achieve this effect? I can’t get the gradient to bend along the path. The mesh tool would be too complicated or messy for this. There must be a simpler method around it.

Would greatly appreciate it if someone could show me the ropes. Thanks a lot.