Does your horse work off your leg? Can you leg yield, move his haunches and shoulders? When you try to get him back on the rail (say tracking left) are you looking directly AT the rail or are you looking to the center of the arena?
When I’m trying to work a spooky horse past a scary spot I never look directly at it. Nor do I ride directly to it. For example, if I’m tracking left and I’m trying to get him on the rail I would never use my right rein. Instead I would first get him working on the bit then use my left rein to bend him left, make him think ‘left’ (but still traveling straight at this point, almost in shoulder fore.) THEN when he’s traveling straight but thinking left I use my left leg to leg yield sideways to the wall. Just a step or two. Continue straight with a slight bend left. Ask for another step or two. Then go straight. Then maybe I would leg yield towards the middle. Straight. Step or two back towards the wall. Repeat.
Instead of pointing him directly at it and riding directly towards what’s scaring him (the moment you focus on it he will immediately pick up it on from your body language) you are focusing your attention on the not so scary center of the arena and asking him to focus there, too. By leg yielding first towards the wall, then away from it you are asking him to use his brain. Throw in some transitions and circles. Ride as if you have no intention of being on the rail. If you get him thinking first and keep his focus on what you are asking him to do instead of where you are asking him to go you should be able to step him right over to the rail. Don’t stay there too long at first. A step or two on the rail is fine and can be built upon slowly.