It's hugely a mental game, like anything else skiing. If you approach the rail thinking about how hard you may bite it, then you probably will. Own the rail, seriously. When i was learning rails, I was told by Skogen Sprang himself (a big name back in the day) that I should say/think "You're mine, you're mine" to the rail over and over in my head as I approached it, and it worked!
Approach the rail with more speed than you think you will need. Speed is your friend, not only are you more stable at speed, it makes the whole ordeal go a lot faster. If you haul ass at a 10 foot flat rail, it's almost impossible to fall off the side. As you come up to the rail with plenty of speed and your head set to boss-mode, pop hard and turn your shoulders parallel with the rail, your feet will naturally follow (don't look down at them to check! looking straight down is what you wanna avoid the whole time). Focus at the end of the rail and wait for your feet to touch down on it. Weight your front foot with a little more body weight than your back when on the rail. Too much weight on the back and you may slip-out backwards. I would say about 60% weight on the leading foot, about 40% in back. It's okay to have equal weight on both feet the first few slides, but get in the habit of weighting the front foot more for when you learn kinked rails or more technical things.