No doubt that painting the rails is much easier and results are better when done prior to laying the track and ballasting. It can be done afterwards, but it does get messy.
I've taken the latter route as I did not consider painting the rails beforehand. I just painted a portion of the inner line, so wanted to show the contrast between painted and unpainted. Atlas track is used here.