If it doesn't come to rest on the bed of the table, it is a foul. Incoming player takes BIH. The top of the rails are not the playing surface.
It is also a foul if the cue ball hits anything on the rail and falls back to the playing surface like chalk cubes and whatever else is on the rail.