How can I attach deck railing boards to the top of the rails?
Glue and Screw
Drill pilot holes from the bottom side of the lower 2x4 all the way through, Clamp the lower 2x4 in place and  use 4 inch deck screws to screw up through the pilot holes and into the bottom of the upper 2x4 . ( 2x4 are only 3 1/2 inches ) so a 4 inch screw will give you enough thread to bite into the upper board just be careful not to drive them to far.
Screwing from the bottom this way will keep all screw heads hidden on the bottom side.
Apply OUTDOOR rated glue. Remove clamps.