The rail is the wooden pole he is driven out of town on
Riding the rail (also called running out of town on a rail) was a punishment of Colonial America in which a man was made to straddle a fence rail held on the shoulders of two men, with other men on either side to keep him upright on the rail. The victim was then paraded around town or taken to the city limits and dumped by the roadside. Injuries from the ride could, if the victim were stripped, result in a cut crotch that often made walking painful.
The punishment was usually a form of mob extrajudicial punishment imposed in connection with tarring and feathering. It was intended to show community displeasure and humiliate the victim so he either conformed his behavior or left. Alternatively the term also referred to tying a person's hands and feet around a rail so the person dangles under the rail.
Other references mention its being used as punishment for Confederate prisoners in Union POW camps during the American Civil War. In these cases, the victims were usually clothed.
I see you understand my references to sharp edges, splinters and springiness... ‘-)