Hi HilaryRose, I too suffer from heartburn fairly regularly when riding. What I have found is RonH is right- the type of food I eat even several hours before a ride causes heartburn.
As I commute, mainly, I eat a plain breakfast am, try not to eat anything too fancy/ spicy/rich through the day.
I did read once that after you have heartburn it takes several weeks for you eusophagus to recoat itself and in that time you should avoid the foods that cause heartburn. I tried this once and my diet was too boring.
So now I just take care through the day and eat what I like after.