How to create material that goes along curved mesh?
If you dont mind you can use just a Curve.
Shape

add Curve Circle, in edit mode Rotate 45, Duplicate and move 2.8 on X axis
select all vertices switch handles to Free V and delete from both circles the center segment
select end points and press F to connect

To get even distribution of colors you need to evenly distribut a curve's control points, that is not right now, but you can add another curve object - straight like, subdivide several times and deform this curve by previously shaped curve.

Add some stickness to curve (tube) - go to Properties editor &gt; Object Data &gt; Geometry &gt;  Bevel &gt; Depth
It is better to keep curve in type Shape &gt; 2D and Fill &gt; None
Add Curve modifier (ensure origins both objects are at the same place)
Moving along X axis will move along shape

2.7x Material

Plug UV Texture Coordinate socket into Separate XYZ node
and use X socket to lug into ColorRamp
Enable under Properties editor &gt; Object Data &gt; Texture Space &gt; Use UV for mapping.

To see material switch to Rendered type view mode.



2.9x Material
is like here, you don't have to worry about UV in curve properties, it is set by default.

Notes:
Changing X Location will move gradient along curve.

Changing X Scale in Mapping node will change gradient scale.