Using ammonia is not a sure shot way to get rid of rats, but it might scare them away for a little bit. This is because ammonia mimics the scent of urine. When rats smell this, they think a fox or a cat is nearby, and run away. Aside from using ammonia to get rid of rats, you should take other precautions, like boarding up holes and sealing up food sources.
How to Get Rid of Rats With Ammonia
Find any areas where rats might be entering your home. You want to scare the rodents away from these areas.
Pour equal amounts of ammonia and water in cups and place them by the entrances, or soak rags in ammonia and place them by the entryways.
Go around the perimeter of your house outside and lay down a line of ammonia as a barrier.
Replace the ammonia solution or rags near the rat entrances every few weeks.