How to change color along a curve?

I have a curve, which has been made visible by using a circle as a bevel object. I would like the color to change along the length of the curve. In other words, the curve will start red, and then change to blue towards the end.

I have figured out how to make the color change as a function of a coordinate (in this case the x-coordinate), but I cannot figure out how to get the coordinate along the length of the curve so that I can pass it to the ColorRamp.

Any ideas?