A severe case of leg cramps can leave you “frozen” on the side of the highway afraid to move a muscle for fear of making the cramps worse! Rest for a while, massage your muscles, and pedal carefully! Muscle cramps are serious but temporary. They are an expected part of getting in shape, in my opinion.
To avoid leg cramps, consume foods which are high in potassium and magnesium. Fruits, vegetables, and unsalted nuts are excellent candidates. Avoid consuming too much salt. I only get leg cramps when I resume riding in the spring after several months of taking it easy and eating out too much.
When you eat at restaurants, you are on a high sodium diet. You can actually see the excess sodium appear as streaks on your clothing when you work out. The “desalination” process takes just a few long, hot days of riding, and then I no longer get leg cramps no matter how hard I ride. Other cyclists have different opinions. Some swear that taking salt tablets cures their leg cramps. I am very skeptical, but perhaps people vary in their metabolic requirements. My approach is based on what works for me.