When I started eating pretzels on long rides, I saw a reduction in leg cramps riding. A lot of cyclists drank V8 on rides too.
I do sort of get them frequently in real life though, but if I eat a lot of spinach (potassium) and take magnesium at night, I don't have them in the middle of the night anymore. I eat a lot of salt.