On my bmx bike, I can ride about 20 feet on a railroad rail or about 5 feet on a tire wide flat rail (2inch wide) Like others said, just look at where your going, go at a comfortable pace, and don't steer with your bars/wheel, use your body to balance over the top of the bike and keep your wheels straight.
I always just practice riding and balancing over curbs to see how long I can stay balanced on them without falling off. you'll gain a lot of confidence.