After King Candy lied to Ralph about his reasons for not letting Vanellope race, Vanellope emerged from inside Diet Cola Mountain and instructed Ralph to lower his head and close his eyes, draping the cookie medal around his neck after he did so. On opening his eyes, Ralph examined the cookie medal and saw that it said "To Stinkbrain," eliciting his annoyance until Vanellope told him to turn it over, revealing the words "You're my Hero." She was worried that she might fail to finish the coming race in First Place, which would forfeit her claim to both the winner's cup and all the coins in the pot, including Ralph's Medal of Heroes. So Vanellope made a "back-up" medal so that whether she won or lost, Ralph could still return to his home game with a hero's award around his neck.
Vanellope's thoughtful gift complicated Ralph's task of keeping his word to King Candy and keeping Vanellope out of the race, and Ralph was clearly wracked with guilt and a heavy heart as he destroyed the kart that he and Vanellope had made together. Ralph later returned home to find everyone gone, as their game was slated to be unplugged because of his actions. Pensively, he looked Vanellope's medal over before throwing his golden Medal of Heroes away, having realized that a gift from the heart is worth far more than a golden prize claimed through cheating and not truly earned.
He later had the cookie medal clutched in his fist as he was plummeting to deliver the final punch that would trigger Diet Cola Mountain's eruption, changing the cola volcano into a beacon that would eradicate the invading Cy-Bugs and save Sugar Rush.