How to fix flaking paint on a deck railing and make it last?
Scrape, sand, prime and then paint with exterior grade products. Longevity of the paint will also be based on the moisture content of the wood at the time you painted it. A handy 'mini-Ligno' moisture meter is used to determine if the wood is dry enough to hold primer and paint. Consult with the paint manufacturer for moisture content recommendations. 

See... Mini-Ligno    http://www.lignomatusa.com/meters/mini-ligno-md/
Long lasting paint... http://www.paintpro.net/Articles/PP503/PP503_CoatingsFailure.cfm