There are three golden rules for successful grammar teaching. Unfortunately, nobody knows what they are. So instead, let me offer a few personal opinions. I'll try to be brief: I've spent the last three years writing a practical grammar course that's moving towards publication, and I've got so much in my head that it's hard to sum it all up.
There's a lot of theory around, much of it contradictory. It can be valuable, but I sometimes feel, to quote Mark Twain, that "the researches of many commentators have already thrown much darkness on this subject, and it is probable that, if they continue, we shall soon know nothing at all about it". My rather unhelpful view is that it all depends. Learners vary greatly in their response to grammar teaching: some get a lot out of it, some very little. Learning contexts and purposes also vary greatly. And 'grammar' means so many different things that it's extremely difficult to generalise about how to teach it.
In general, I have little sympathy with people who are hostile to giving students rules. Explanations of how things work are often useful. They do need to be clear and simple, though: the whole truth can be counterproductive, in language as in life. I get uneasy if an explanation in a book for learners takes up more than two or three lines of text. They should be in the mother tongue if possible. Some points can be usefully learnt through an inductive 'discovery' approach, others probably not.
Good realistic examples are vital, but they don't replace explanations – an example on its own never tells you exactly what it's an example of. Suitably chosen authentic material – advertisements, cartoons, songs, poems, etc – can make examples memorable and fix them in students' minds. I've often found it helpful myself to learn examples by heart – they act as a sort of template for generating similar phrases or sentences – and I think this is true for many learners.
Variety is really the key. There's nothing wrong with mechanical exercises – gap-filling, sentence transformation and so forth. These can help learners to grasp the form of a complex structure at the outset without having to think too much about the meaning. But it's important to move on to activities where the structure is used in more interesting and realistic ways. I like structure-oriented problem-solving activities and quizzes, games, picture-based work, text-based work, role-play, exercises that get students using the structure to talk about themselves and their ideas, exercises that combine grammar practice with vocabulary learning, and internet-exploration activities, to name just a few approaches.
Supplementing the coursebook
The coursebook (if there is one) generally won't provide enough work on key points. More practice will be needed in class, using groupwork and pairwork. Out-of-class work (corrected or self-access) using good grammar practice materials can also help a lot.
The real problem, of course, is getting learners to carry over their grammar learning from controlled practice to spontaneous real-life use. They get their tenses all right in the grammar exercises on Tuesday morning, and all wrong in the discussion on Friday afternoon. Up to a point, we have to live with disappointment: foreign-language learners don't get everything right. We certainly need to keep coming back to key grammar points, revising them, practising them in semi-controlled speaking and writing activities, and correcting mistakes by whatever approach we find most useful, but we won't get anything like complete accuracy. (My basic view of grammar teaching is that if we teach some grammatical structures to some students, some of them will get better at using some of those structures some of the time. Definitely.) I think we also need to respect students' decisions. If they have learnt when to use third-person -s, have had plenty of practice, have had their mistakes corrected, and still go on dropping it – well, that is their choice, and we shouldn't waste any more time on the point, or beat ourselves up because we haven't got the students to do what we want. Life is too short.