There is a pretty good account of how this works in Karl Schwede's paper:
MR2182775 (2006j:14003)
Karl Schwede, Gluing schemes and a scheme without closed points.
Recent progress in arithmetic and algebraic geometry, 157–172, Contemp. Math., 386, Amer. Math. Soc., Providence, RI, 2005