I think it's largely genetic.
I can go 40-60 mi on just water, no problem, but the more sedentary other half frequently gets muscle cramps.
Pineapple juice is her cure of choice. Those little 6 oz cans are packed with potassium. Works for her, (or at least the placibo effect does)
Dried apricots are also really high in potassium and I've used those for cramp prevention on mountaineering ventures that were a lot more intense than cycling.
Seemed to work, if you need a lighter to pack source.