why $\mathbb{Q}[x]= \mathbb{Q}(x)?$ Theorem :  If  $x$  is  algebraic over $\mathbb{Q} $, then  $\mathbb{Q}[x]= \mathbb{Q}(x)$
My doubt : Here $\mathbb{Q}(x)$ is field  and $\mathbb{Q}[x]$ is not field  since $\frac{1}{x} \notin \mathbb{Q} $ but $\mathbb{Q}[x]$ is ring
we know  that  field  $\neq$  ring
Then why  $\mathbb{Q}[x]= \mathbb{Q}(x)?$

Take $f(x)=x^2 +1 \in \mathbb{Q}[x]$.
$x^2+1=0 \implies x= i$
Here
$$\frac{\mathbb{Q}[x]}{f(x)} \cong \mathbb{Q}[i]$$
since $\langle f(x)\rangle$  is  maximal  $\implies \mathbb{Q}[i] \subseteq \mathbb{Q}(i) \tag1$
Also $x^{-1} \in \mathbb{Q}[x]$ this $\implies \mathbb{Q}(i) \subseteq \mathbb{Q}[i]\tag2$
From $(1)$ and $(2)$ we have $\mathbb{Q}[i] = \mathbb{Q}(i)$
