The phrase is used metaphorically to mean returning to the right path, like a train back on tracks. She lost focus during her studies, but finally got back on the rails.
Pro Tip 2/3
Positive Connotation
This phrase carries a positive meaning, suggesting improvement or correction of a situation. After the budget review, our finances got back on the rails.
Pro Tip 3/3
Not Literal
Don't confuse it with its literal meaning; it's not about actual rails, but about fixing problems. The production line failed, but we got it back on the rails in no time.