Hartshorne Algebraic Geometry Exercise II.2.16. For part a) of this exercise we need to show that for a scheme $X$ and an open affine subset $U=$ Spec $B$ that $U \cap X_f = D(\bar{f})$ where $\bar{f}$ is the restriction of $f \in \mathcal O_X(X)$ to $\mathcal O_X(U)$ and $X_f= \{x \in X :$ the stalk of $f$ at $x$ $(f_x)$ is not contained in the maximal ideal $(m_x)$  of $\mathcal O_x \}$.
Now I believe the proof goes something along the lines of using the fact that this maximal ideal in the affine scheme is just $xB_x$ but I can't see how $f_x \not\in m_x$ implies $\bar{f}_x \not\in xB_x$. Like how can we go from the local ring $\mathcal O_x$ to $B_x$?
 A: Note that for any $x\in U$ we have $\bar{f}_{x}=f_{x}\in \mathcal{O}_{x}=B_{x}$ and $\mathfrak{m}_{x}=xB_{x}$. This holds by definition of the colimit: the open neighbourhoods of $x$ contianed in $U$ are a cofinal family. But then we have $f_{x}\in \mathfrak{m}_{x}$ if and only if $\bar{f}_{x}\in xB_{x}$, so that $U\cap X_{f}=\{ x\in \operatorname{Spec}{B} \mid \bar{f}_{x}\notin xB_{x}\} $, i.e. those prime ideals such that $\bar{f}$ is invertible in the corresponding localization, which means precisely that $\bar{f}$ is not in the prime ideal. Hence $D(\bar{f})$.
Edit: (why is $\mathcal{O}_{x}=B_{x}$?)
By definition, $\mathcal{O}_{x}$ is the direct limit
$$ \mathcal{O}_{x}=\lim_{x\in V\subseteq X}\mathcal{O}(V)$$
This means that we look at smaller and smaller neighbourhoods and we identify sections with their corresponding restrictions. We do this until we get the germs $f_{x}\in \mathcal{O}_{x}$, which are by definition equivalence classes represented by pairs $(V,s)$ with $V$ an open neighborhood of $x\in X$ and $s\in \mathcal{O}(V)$ under the equivalence relation $(V_{1},s)\sim (V_{2},t)$ if and only if we may find an open neighbourhood $W\subseteq V_{1}\cap V_{2}$ of $x\in X$ such that $s|_{W}=t|_{W}$.
Since $U=\operatorname{Spec}{B}$ is an open neighborhood of $x\in X$, any $(V,s)$ is related to $(V\cap U, s|_{V\cap U})$. Therefore
$$ \lim_{x\in V\subseteq X}\mathcal{O}_{X}(V)=\lim_{x\in V\subseteq \operatorname{Spec}{B}}\mathcal{O}_{\operatorname{Spec}{B}}(V) $$
This last expression is $B_{x}$ by construction of the affine scheme $(\operatorname{Spec}{B},\mathcal{O}_{\operatorname{Spec}{B}})$.
This is a particular case of cofinal family. These are useful to compute colimits in many situations. Another useful example: affine open subsets are also a cofinal family, since they form a basis for the topology. So cofinal means the following: you are taking the direct limit over some directed set $(I,\leqslant)$, that is, a partially ordered set such that every two elements have an upper bound. A subset $J\subseteq I$ is called cofinal if every $i\in I$ is bounded above by some $j\in J$. The (sub)family indexed by $J$ is then called a cofinal family, and we may compute the colimit over this new indexing set.
