Rats are opportunists. If they have the choice between a food that will need a fight to get, and another food that will not, they take the food that does not need a fight. For this reason, rats have lived close to humans for a long time. Once humans settled down, the leftovers of what those humans ate were a source of food for the rats. So the rats followed.