Consider a quantum particle on a ring and a non-zero homogeneous magnetic field perpendicular to the disk that the ring defines and is non-zero only in the inside of the perimeter of the ring. Let $\vec{B}=B_0 \hat{z}$ and the flux through the ring be $\Phi$.
For the vector potential, we can choose (in cylindrical coordinates) $\vec{A}=\dfrac{\Phi}{2\pi}\dfrac{1}{\rho}\hat{\phi}$.
If I try to perform a gauge-transformation $\vec{A'}=\vec{A}-\vec{\nabla}f$ to gauge-away the magnetic field by going to a new gauge where $\vec{A'}=\vec{0}$, I find $f=\dfrac{\Phi}{2\pi}\phi$. So, since I have found a function $f$ to do this, it seems as if I have successfully gauged-away the magnetic field, which is physically impossible!
What is happening here?
I suspect that something is not right because $f$ is multi-valued at $x=0$ (which corresponds to $\phi=0, 2\pi, ..)$. If this is the case, how do I fix this and get $\vec{A'}\neq0$? Is there a systematic way to treat cases such as this, i.e. to find a proper $f$ that would deal with this problem and give the correct magnetic field?