I had a similar injury with my big toe on my foot. Half of my toe nail was ripped off. First thing to do is clip away as much of the detatched part of the nail as you can.
If all of the nail ripped off, you should go to the doctor's. If only part ripped off, there is no need to go to the doctor's. Simply clip away the part of the nail that is seperated from the nail bed.
You may need to use a paperclip and slide it under the nail to be able to tell exactly how far it detatched itself. Just keep going under it with the pin and clip off as you go. Once you have clipped off as much as you possibly can, get yourself some polysporin cream. Use a cream, not an ointment because the cream dries up faster, with the ointment you will just create moisture which will not allow it to heal properly. Also, do not soak it in epson salts and whatnot. Also try to avoid covering it up because that doesn't allow it to breathe. After, all you will need to do is wait. Simply leave it to heal. Apply polysporin cream 3 times a day. You can also bandage it up when you go out, with a nonstick pad, and some gauze wrap. You should stop feeling pain, depending on how badly you injured it, within a week or so.
Going to the doctor's is useless, they will probably tell you exactly what I have just told you. Unless, all of your nail was ripped, you should probably go so they can properly remove it without damaging the matrix.