Rails protect people from falling... off porches, out of bed, down the steps, out of a tree house or gazebo.
Rails are generally used to keep a handle or an precaution on climbing stairs or setting barriers to prevent accidents of falling over.
Rails may also refer to the tracks that trains go on.
If someone is said to to go "off the rail", it means that they lose control and starts behaving in a way that may be deemed unacceptable, or it may also mean that someone has lost all sight of reality and gone into a world that is seen as not real.