The wire is wrapped around the nail as many times as possible. Then one end of the wire is attached to one lead of the battery clip while the other end of the wire is attached to the resistor which is then attached to the other end of the battery clip. Once the battery is put in the clip, the nail will act as a magnet, with one end a north pole and the other a south pole.
Any wire emits a magnetic field, even long straight wires or a coil of wire without the nail. You should find that the magnet is strongest with the nail in place. The reason is that, in the presence of the magnetic field of the wire, the iron magnetizes.
Notes and Safety
Possible Background Demonstration