Every finitely generated flat module over a ring with a finite number of minimal primes is projective

Upon request, I repost my MathOverflow answer (c.f. MO/218737). There are two questions here, namely, whether the argument given in the question is okay, and whether the criterion really is more general than the one by Raynaud-Gruson. The answer to both questions is yes. The following holds:

Let $A$ be a commutative with unity and $M$ a flat finitely generated $A$-module. Then the rank function $\mathrm{Spec}(A)\to\mathbb{N}_0$, $\mathfrak{p}\mapsto \mathrm{rk}_{A_\mathfrak{p}}(M_{\mathfrak{p}})$, is constant on all irreducible components of $\mathrm{Spec}(A)$. In particular, if $\mathrm{Spec}(A)$ has finitely many maximal irreducible components (i.e., if $A$ has finitely many minimal prime ideals), then the rank function is locally constant, hence $M$ is projective.

The (very nice and short) proof was given by the OP in the question text and in a comment. (With the same arguments, one can further generalise this to schemes; see loc. cit.)

The criterion by Raynaud-Gruson requires finitely many associated primes, so to be sure that the above criterion is more general, we need an example of a ring with finitely many minimal, but infinitely many associated prime ideals. The following example has a single minimal prime ideal, but infinitely many associated prime ideals. Picture it as a line with infinitely many embedded points. (Just as $k[x,t]/(t^2,xt)$ has associated primes $(t)$, the unique minimal one, and $(x,t)$, the "embedded point".)

Let $H$ be the ring of holomorphic functions on the complex line $\mathbb{C}$ (with coordinate $z$) and $f\in H$ a non-trivial holomorphic function with infinitely many zeros (e.g., $f(z) = \sin(z)$). We consider the ring $A:=H[t]/(t^2,tf)$. Since $A/(t)\cong H$ is an integral domain, the ideal $(t)$ is prime. On the other hand, this ideal happens to be the nilradical of $A$, which is the intersection of all prime ideals; thus, $(t)$ is the only minimal prime. However, for each root $\alpha\in\mathbb{C}$ of $f$ we recognise the associated prime ideal $(t,z-\alpha)\subset A$, so there are infinitely many of them. In fact, if $g\in H$ is the unique entire function with $(z-\alpha)g = f$, then it is easy to see that $(t,z-\alpha) = \mathrm{ann}_{A}(tg)$.