I'm assuming you are not talking about urban rails so here is what the trick tip cult says about it:
Trick tip: MADDECENT
1. Approach the rail with your feet wide
2. POP before you begin to turn sideways, don't rush it.
3. As your tails leave the ground, turn sideways. Be looking at the end of the rail throughout the entire rail. When you are first learning, focus on keeping your shoulders facing downhill and having your lower body turned perpendicular to the rail. This will help drastically with keeping you on the rail the entire way.
4. Land on the rail with your feet wide and your knees bent. The vast majority of people will be used to hockey stopping on snow, so when they try to grind, they will lean back on their uphill edges and slip back. Some people teach 60% of your weight on your back foot, 40% on your front, but I say 50/50.
5. Keep wide feet, low stance, looking at the end of the rail, and with a few tries you'll have it down
I would recommend joining this cult, it is very helpful