Rats are naturally cautious creatures. The sudden appearance of a trap (or anything else) will cause them to avoid the trap until they become accustomed to it. Whether you're using live traps or some other type of humane trap, the use of rat baits can help lure the rats to the trap. Food is the most attractive bait to use - but the best type of food bait depends on the type of rat you have.
One thing to remember is that bait needs to be replaced to keep it fresh, as fresh food is much more enticing to rats. This can be difficult if traps are placed in inaccessible (or hard-to-access) areas. Therefore the type of bait chosen has to be practical as well; if it's likely to spoil quickly, then some other type of food may need to be used. Peanut butter is often a good choice except in hot areas which can cause it to spoil quickly. Compromises can include peanuts (instead of peanut butter) or dried fruit (instead of fresh fruit).
You can also trying offering nesting materials instead, like cotton or dental floss. Regardless of the bait used, traps must be properly set in order to work as intended - even humane traps can be dangerous if not used correctly.
Choosing rat baits is just one small part of figuring out how to get rid of rats in the house. Many humane pest control methods are available, and homeowners should also familiarize themselves with how to exclude rodents from the home. Prevention and maintenance are ultimately the most humane and most effective ways to prevent a rat or rodent infestation.