I would probably trap and kill the rats.
Are you paying attention to your greens and browns? I never had to in our old house, because the compost pile was under a tree that dumped browns into the bin automatically. Very handy. But in this house, I have had to deal with it. Our compost pile was getting nasty. Like something died in their rotten stinky. Once I started adding browns, it went away and broke down more quickly, eliminating the attraction to pests. I also found that if I put the food scraps on top, raccoons would sometimes come eat from the fresh stuff on the top. But if I cover it with shredded newspaper or leaves, they leave it alone.
Fun compost story: the neighbors behind us are unfriendly at best. They hate anything we do in our yard, and blamed us for making their view ugly. When we started our compost pile, the neighbors complained. They escalated their complaints to the HOA, who had approved it and told them to stuff it. (Well I like to imagine that last part). The next thing I know, the health department showed up. They had complained to the health department that our compost pile was a "vector for disease". Health department guy made a halfhearted effort to convince me to buy a roller bin, and I told him,sure, he can buy me three and I will use them, but 1. They are $$$$, and 2. They fill up so fast. Then he told me that I was just required to limit access (i have a chicken wire fence around it, although it's pointless since most pests can climb over that) and keep it covered with leaves, grass clippings, etc. The neighbors have been quiet since that incident, but I try to drop phrases like "vector for disease" and "health department-approved compost pile" into conversations whenever possible.