What does 'Off the rails' mean?

If someone has gone off the rails, they have lost track of reality.

See also: