The answer to 'how to prevent rat' is to take a comprehensive approach to rat-proofing your home. This involves sealing up entry points, removing food sources, and using humane deterrents. Start by inspecting the exterior of your home and sealing any cracks or holes larger than 1/4 inch, which is the size a rat can squeeze through. Use caulk, steel wool, or other durable materials to close these gaps.
Next, eliminate food sources by storing all food in airtight containers, cleaning up spills and crumbs, and keeping trash in sealed bins. Rats are attracted to easy access to food, so depriving them of this will discourage them from entering your home. You can also use deterrents like ultrasonic devices or natural repellents like peppermint oil or ammonia-soaked rags to keep rats away.