Discourage any inappropriate behaviour from the outset. Avoid flirtatious conversations which may give your boss the wrong hints. Change the topic if possible and keep physical distance in discussions, since undue contact can also convey the wrong messages.
Make sure that you build only a work related relationship with all your co-workers. Being friendly with a few and cold with others will leave a bad image. If you are already in a relationship, it is important to clear your position with everyone so that your boss understands that you are not interested.
In case you are single, avoid spending too much time with your boss. Meet him when necessary or when there are other people around you. If your boss tries to be cheeky, make sure to clear the air. Have a positive conversation with him about the matter and avoid a heated argument. If the word spreads out, that does not bode well for you. Getting on the wrong side of your boss could mean that your days with the company are numbered.
Keep your cool and don’t make your boss feel bad or embarrassed. Being gentle is the right way but make sure you clear your stance. Do not be rude and try to pass casual comments, hinting towards your lack of interest in any such relation. Stating your intent clearly, without disrespecting your boss may turn out to be positive, where your working relationship could become stronger.
If you feel that the situation is getting worse, contact a legal person in your company or the human resources department. This option must be exercised in the worst case scenario because it will open a possible case which may have serious implications for you and your boss