Gluing affine schemes Let $Y$ be a scheme, and $\mathcal{A}$ be a sheaf of $\mathcal{O}_Y$-algebras. Such that $\mathcal{A}$ is quasi-coherent. 
For every affine open set $V$ in $Y$, we have ring morphisms $\mathcal{O}_Y(V) \to \mathcal{A}(V)$ which induces $\text{spec}  \mathcal{A}(V) \to \text{spec} \mathcal{O}_Y(V) $. Now $\text{spec} \mathcal{O}_Y(V)\simeq V$ naturally. Thus, we have a collection of natural scheme morphisms $f_V: \text{spec}  \mathcal{A}(V) \to V$. 
Construct $X$ to be a topological space obtained gluing each of the $f_V$ maps. Therefore, one has continuous map $\lambda_V: \text{spec}  \mathcal{A}(V) \to X$, and $f:X\to Y$, such that $f_V = f\circ \lambda_V$. 
Denote by $X_V$ to be the image of $\lambda_V$, this is an open subset of $X$ homeomorphic to $\text{spec}  \mathcal{A}(V)$. One can then push the structure sheaf and construct $(X_V,F_V)$ which is a scheme. 
The open sets $X_V$ cover $X$, and over each one there is a sheaf $F_V$. Can one glue these sheaves $F_V$ together here? 
In order to glue, one requires morphisms $\varphi_{VU}:F_V|_{X_V\cap X_U} \to F_U|_{X_V\cap X_U}$, which satisfy the co-cycle condition. 
Let $W$ be an open set in $X_V\cap X_U$, then $\lambda^{-1}_VW$ is open in  $\text{spec}  \mathcal{A}(V)$ and $\lambda^{-1}_UW$ is open in $\text{spec}  \mathcal{A}(U)$. These two schemes $\lambda^{-1}_VW$ and $\lambda^{-1}_UW$ are isomorphic. 
But how does one construct an isomorphism between them that would carry over and give us the desired morphism between $F_V$ and $F_U$ satisfying the co-cycle condition?  
 A: I just want to correct one mistake in my counterexample, and I want to make another philosophical point.  First, you do need some hypothesis such as quasi-coherence of $\mathcal{A}$.  The counterexample I wrote is wrong; here is a correction.  Let $Y$ be $\mathbb{A}^1_k = \text{Spec}\ k[t]$.  Let $0$ be the closed point with corresponding maximal ideal $\langle t \rangle \subset k[t]$.  Let $\mathcal{A}$ be the $\mathcal{O}_Y$-module such that $\mathcal{A}(U)$ is $\{0\} = k[t]/\langle 1 \rangle$ if $U$ does not contain $0$, and such that $\mathcal{A}(U) = k(t)$ as a $k[t]$-algebra if $U$ does contain $0$.  For open subsets $V\subset U$, the restriction homomorphism $\mathcal{A}(U)\to\mathcal{A}(V)$ is either zero, if $V$ does not contain $0$, or the identity on $k(t)$ if $V$ does contain $0$.  It is straightforward to check that this is a sheaf (this is the mistake in my previous example).  For every open affine $U\subset Y$, there is a natural morphism $$f_U:\text{Spec}\ \mathcal{A}(U) \to U,$$ and for every pair of open affines $V\subset U \subset Y$, there is a natural commutative diagram, $$\begin{array}{ccc} \text{Spec}\ \mathcal{A}(V) & \xrightarrow{f_V} & V \\ \downarrow & & \downarrow \\ \text{Spec}\ \mathcal{A}(U) & \xrightarrow{f_U} & U \end{array}.$$  However, this commutative diagram is not a fiber product diagram: if $U$ contains $0$ but $V$ does not, the fiber product is $\text{Spec}\ k(t)$, but $\mathcal{A}(V)$ is the zero ring.  Therefore, there is no morphism $f:X\to Y$ and collection of isomorphisms $$\phi_U:f^{-1}(U) \xrightarrow{\cong} \text{Spec}\ \mathcal{A}(U),$$ as schemes over $U$.  If there were, then $\text{Spec}\ \mathcal{A}(V)$ as above would be $f^{-1}(V)$, and this is the fiber product of $f^{-1}(U)\to U$ and $V\to U$.
Now here is the philosophical point.  One way to "calibrate" the gluing is to write down a universal property satisfied by the glued object and that is compatible with restricting to open subsets.  In this case, the universal property of $f:X\to Y$ is that there is a homomorphism of $\mathcal{O}_X$-algebras, $s:f^*\mathcal{A}\to \mathcal{O}_X$, and this is universal: for every $g:Z\to Y$ and homomorphism of $\mathcal{O}_Z$-algebras, $t:g^*\mathcal{A}\to \mathcal{O}_Z$, there exists a unique morphism $h:Z\to X$ such that $f\circ h$ equals $g$ and such that $t$ equals $h^*s:h^*f^*\mathcal{A}\to h^*\mathcal{O}_X$.  In the quasi-coherent case, where locally $\mathcal{A}_U = \widetilde{A_U}$ for an $\mathcal{O}_Y(U)$-algebra $A_U$, it is straightforward to check that locally $\text{Spec}\ \mathcal{A}(U) \to U$ satisfies the universal property.  Then, for open affines $U$ and $V$, the corresponding universal properties give an isomorphism of $f_U^{-1}(U\cap V)$ and $f_V^{-1}(U\cap V)$ as schemes over $U\cap V$.  Finally, the uniqueness part of the universal property implies the cocycle condition for these isomorphisms.
A: I am going to follow the method suggested by Jason Starr. Unfortunately, I reach a dead-end in the proof, hopefully one of you can help me fix it. 
Note: I modified the universal property that we want. Because I want to be consistent with Hartshorne Exercise 2.5.17. 

Let $(Y,\mathcal{O}_Y)$ be a scheme with $\mathscr{A}$ a quasi-coherent sheaf of $\mathcal{O}_Y$-algebras. We denote by $\text{spec } \mathscr{A}$ to be a scheme $X$, for which we have a scheme morphism $f:X\to Y$, and a collection of isomorphisms $\theta_V:f^{-1}V \to \text{spec }\mathscr{A}(V)$ for each open affine $V$ in $Y$, such that if $V\subseteq U$ then the following diagram commutes, 
$$\require{AMScd}
\begin{CD} f^{-1} V @>>> f^{-1} U \\ 
              @V\theta_{V} VV           @VV \theta_U V \\
       \text{spec } \mathscr{A}(V) @>>> \text{spec } \mathscr{A}(U) \end{CD} $$
Furthermore, we require $X$ to have the following universal property. If $Z$ is any scheme for which we have a morphism $g:Z\to Y$, and a natural collection of isomorphisms $\zeta_V:g^{-1}V\to \text{spec } \mathscr{A}(V)$, then there exists a unique morphism $h:Z\to X$ such that $g = f\circ h$ and such that $\zeta_V  = \theta_V\circ h_V$ (in the second equation, $h$ is being restricted to $h_V:g^{-1}V \to f^{-1}V$). 
Clearly, by abstract non-sense if $X$ exists it is unique, so the question remains that of existence. We first focus on the case when $Y$ is an affine scheme, so $Y = (\text{spec } A, \widetilde{A})$ for some ring $A$. The quasicoherent sheaf $\mathscr{A}$ is then of the form $\mathscr{A} = \widetilde{B}$ for some algebra $B$ over $A$, say given the ring homomorphism $f':A\to B$. Thus, one obtains a scheme morphism $f:\text{spec } B \to \text{spec } A$, and we claim that $\text{spec } B$ will satisfy the required universal property above. One now has to define a natural family of isomorphisms $\theta_V: f^{-1}V\to \text{spec } \mathscr{A}(V)$ for each affine open set $V$ in $Y=\text{spec } A$. First say $V = D(a)$, a basic open set in $Y$, for some $a\in A$. Then $f^{-1}V = D(f'(a))$ a basic open set in $X$. Now $\mathscr{A}(V) = \widetilde{B}(D(a)) = B_a$. A simple algebra exercise will show that the localization $B_a = B_{f'(a)}$. Hence, we need a natural isomorphism $\theta_{D(a)}: D(f'(a)) \to \text{spec } B_{f'(a)}$, which we certainly have (from applying spec to the localization map $B\to B_{f'(a)}$, cf. Exercise 2.1.). 
Here is the nice thing about our family $\theta_V$, $V$ basic open, of isomorphisms so far. They are compatible with restriction. That is to say, if $V\subseteq U$ are basic open sets, then the required commutative diagram will be satisfied. But how do we construct the isomorphism $\theta_V$ when $V$ is a more complicated affine set? One invokes the following Lemma which is left unproved as an exercise. 
Lemma. Let $f:X\to Y$ be a continuous map of schemes. Let $V_i$ be a collection of open sets which covers a scheme $Y$. For each $i$ we have a scheme (iso)morphism $(f,\theta_i):f^{-1}V_i \to V_i$, where the topological map is given by $f$, and $\theta_i$ is a morphism of structure sheaves
. These (iso)morphisms satisfy: if $V_i\subseteq V_j$ then the dia. com.,
$$ \begin{CD} \mathcal{O}_Y(V_j) @>>> \mathcal{O}_Y(V_i) \\ 
              @V\theta_j VV     @VV \theta_i V \\ 
       \mathcal{O}_X(f^{-1}V_j) @>>> \mathcal{O}_X(f^{-1}V_i) \end{CD}$$ 
Under these hypothesis there exists an (iso)morphism $(f,\theta):X\to Y$. Furthermore, this (iso)morphism is also compatible with restriction. 
Now to see why $X$ satisfies the required universal property. Let $h:Z\to Y$ be a scheme for which we have a natural collection of isomorphisms $\zeta_V:h^{-1}V\to \text{spec } \mathscr{A}(V)$. By choosing $V=Y$ we obtain an isomorphism $\zeta_Y:Z\to \text{spec } B$. Call $h=\zeta_Y$. We check that $h$ satisfies $g = f\circ h$ and $\zeta_V = \theta_V\circ h_V$. By choosing $V=Y$, $h_Y = h$ and $\theta_Y = \text{id}$, so we get $\zeta_Y = \text{id}\circ h$ which is true since we defined $h = \zeta_Y$. Therefore, one has to only verify the condition $\zeta_V = \theta_V\circ h_V$. 
By using $V\subseteq Y$, where $V$ is any affine open in $Y$, we get a com. dia.,
$$ \begin{CD} g^{-1} V @>i>> Z \\ 
               @V\zeta_{V} VV @V  V h V \\
       \text{spec }\mathscr{A}(V) @>>> X \\ 
        @V\theta_{V}^{-1} VV @VV\text{id}V \\
       f^{-1}V @>>j> X \end{CD} $$
From this diagram we see that $\theta_V^{-1}\circ \zeta_V:g^{-1}V\to f^{-1}V$ and $h_V:g^{-1}V\to f^{-1}V$ are equal. Thus, we obtain $\zeta_V = \theta_V\circ h_V$ as required.  
Thus, $\text{spec } \mathscr{A}$ exists in the case when $Y$ is an affine scheme and it is given by $\text{spec } B$. For the next part of the proof we show that if $Y$ is a scheme with a quasi-coherent sheaf $\mathscr{A}$ of $\mathcal{O}_Y$-algebras, and $U$ is an open subset of $Y$, then $\text{spec } \mathscr{A}|_U$ exists when we restrict the sheaf $\mathscr{A}$ to the scheme $U$. In fact, if $f:X\to Y$ is our universal map where $X=\text{spec }\mathscr{A}$, then $f^{-1}U = \text{spec } \mathscr{A}|_U$. Since $X = \text{spec } \mathscr{A}$, for each affine open set $V$ in $Y$, we have a natural collection of isomorphisms $\theta_V: f^{-1}V\to \text{spec } \mathscr{A}(V)$. By choosing those affine open sets contained in $U$, the collection $\{ \theta_V \}|_{V\subseteq U}$ is a natural collection, for the scheme $U$ with quasicoherent $\mathcal{O}_Y|_U$-algebra given by $\mathscr{A}|_U$.
One has a scheme morphism $f^{-1}U\to U$ given by restriction called $f_U$, and the natural collection $\{ \theta_V \}|_{V\subseteq U}$. We will show that these two satisfy the universal property for $\text{spec } \mathscr{A}|_U$. We suppose that there is a scheme $S$ together with a morphism $g:S\to U$ and a natural collection of isomorphism $\sigma_V:g^{-1}V\to \text{spec } \mathscr{A}(V)$, for every open affine $V$ contained in $U$. We seek to exhibit a morphism $h:S\to f^{-1}U$, such that $g = f_U\circ h$ and $\sigma_V = \theta_V \circ h_V$. 
Here are the problems. 
(i) How do I complete the proof that $f^{-1}U$ is the relative spec of $\mathscr{A}|_U$? 
(ii) It seems in my approach I require the assumption that $Y$ is separated? 
