A fact about the rank of a module over an integral domain

Let $R$ be an integral domain with quotient field $F$ and let $M$ be any (left, unital) $R$-module. Prove that the rank of $M$ equals the dimension of $F \otimes_R M$ over $F$.

Recall that the rank of a module over a domain is the maximal number of $R$-linearly independent elements.

Suppose $B \subseteq M$ is an $R$-linearly independent set, and consider $B^\prime \subseteq F \otimes_R M$ consisting of the tensors $1 \otimes b$ for each $b \in B$. Suppose $\sum \alpha_i (1 \otimes b_i) = 0$. For some $\alpha_i \in F$. Clearing denominators, we have $\sum r_i ( 1 \otimes b_i) = 0$ for some $r_i \in R$. Now $\sum 1 \otimes r_ib_i = 0$, and we have $1 \otimes \sum r_ib_i = 0$. By this previous exercise, there exists a nonzero $r \in R$ such that $\sum rr_ib_i = 0$. Since $B$ is linearly independent, we have $rr_i = 0$ for each $i$, and since $r \neq 0$ and $R$ is a domain, $r_i = 0$ for each $i$. Thus $\alpha_i = 0$ (since the denominators of each $\alpha_i$ are nonzero). So $B^\prime$ is $F$-linearly independent in $F \otimes_R M$. In particular, we have $\mathsf{rank}_R(M) \leq \mathsf{dim}_F(F \otimes_R M)$.

Now note that if $b_i^\prime = \sum \alpha_{i,j} \otimes m_{i,j} \in F \otimes_R M$, is a linearly independent set, with $\alpha_{i,j} = r_{i,j}/s_{i,j}$, then ‘clearing denominators’ by multiplying $b_i^\prime$ by $\prod_j s_{i,j}$, we have a second linearly independent set with the same cardinality whose elements are of the form $1 \otimes m_i$ for some $m \in M$. Suppose there exist $r_i \in R$ such that $\sum r_im_i = 0$; then $\sum r_i(1 \otimes b_i) = 0$, and (since the $1 \otimes b_i$ form a basis) we have $r_i = 0$. So the $m_i$ are $R$-linearly independent in $M$. Thus $\mathsf{rank}_R(M) \geq \mathsf{dim}_F(R \otimes_R M)$.