Let $R$ be PID, let $M$ be a torsion $R$-module and $p$ be prime in $R$. Prove that $M$ is (possibly infinite) direct sum of its $p$-primary components as $p$ runs over all primes of $R$.
Take $m \in M$. Then $m$ is contained in finitely generated $R$-submodule, $Rm$. Then, consider $Ann(N)$. As $N$ is finitely generated, $Ann(N)$ is nonzero. $N = N_{p_1} \oplus N_{p_2} \oplus \cdots \oplus N_{p_k}$ for some prime $p_i$. Then, we have the isomorphism $\xi: N \rightarrow \oplus_{p_i} N_{p_i}$. Define, natural embedding of $N_{p_i}$. $\rho_{p_i} : N_{p_i} \rightarrow M_{p_i}$ where $M_{p_i}$ is $p_i$-primary component of $M$. Define $\phi: M \rightarrow \oplus_{p_i} M_{p_i}$ as $\phi(m) = (\oplus \rho_{p_i} \circ \xi)(m)$. Observe, $\phi$ is homomorphism since it is a composition of homomorphism. Since the sum is direct in $\xi(m)$ and each $\rho_{p_i}$ embeds to $M_{p_i}$ the homomorphism is injective.
I have found this argument and was trying to fill in the rest to understand. But, I have trouble seeing why $\phi$ is surjective.
Any help would be appreciated!
Your $\phi$ is surjective because if $m\in M_{p_i}\subset M$ for some $i$ then $\phi(m)=f(m)$ under the natural injection $f:M_{p_i}\rightarrow \bigoplus M_{p_j}$. Since $\bigoplus M_{p_j}$ is generated by such elements, the result ensues.
The problem with your argument is actually to show that $\varphi$ is a morphism : it is not as trivial as you claim, be cause you define $\phi(m) = (\oplus \rho_{p_i} \circ \xi)(m)$ where $\rho_{p_i}$ and $\xi$ depend on $m$. You could say that you define $\phi_m(x) = (\oplus \rho_{p_i} \circ \xi)(x)$, which is a morphism, and then $\phi(m) = \phi_m(m)$, which is not obviously a morphism (it actually is, in this case, but this requires an argument).
The thing is, the argument can actually be formulated in a simpler way. Theere is a canonical map $\bigoplus M_{p_i}\rightarrow M$ which is the direct sum of the inclusion maps. It is injective because the $M_{p_i}$ are precisely in direct sum (which can be seen from a Bezout relation for instance).
It remains to show that it is surjective, which means that every element of $M$ is the sum of elements with $p_i$-primary torsion. But this is true for any $m\in M$ since it is true in the finitely generated submodule $R\cdot m$.
Generally speaking, you should never try to define maps to a direct sum, but always from a direct sum (because direct sums are coproducts, they satisfy universal properties as a source of morphisms).