After you beat the team rocket base in the souvenir shop in Mahogany town, go east to Blackthorn city. That is the location of the 8th gym. It is a dragon type gym. After you beat the leader, she will not give you the badge. She will leave. Then go to a place called Dragon's Den right behind the gym. Inside, there will be a cave with a house on a pier. If you go in, there will be an old man who asks you a couple of questions. If you get them right, the gym leader will come and say "How did you get them right? Not even I did!" or something like that. Then she will give you the badge!