While occasionally, for a severe imbalance in the local rat population, trapping may be necessary, in organic gardening it is important to try to work with nature as much as possible. If there are too many rats in the vicinity, this is likely due to a lack of natural predators for the rodents. To rid yourself of rats, owls are your best bet. Encourage tawny and barn owls to live on or near your property. Erect owl nesting boxes high up but as close as possible to the locations where you have seen rats. Foxes can also be a good natural predator for rats, though of course if you keep chickens then the fox will not be a friend. Some pet dogs are also good ratters.
The usual advice with a rat infestation is to remove whatever the rats are eating. If they are eating the vegetable scraps from your compost heap then you may wish to consider using an inside composting bin or wormery to deal with kitchen scraps before you place them on the heap. A sealed compost bin may also be a partial solution, though if it is open to soil at the bottom (usually recommended to allow worms and other beneficial soil organisms to enter) then rats may still dig their way in.
If rats have actually nested in your compost heap then this is a sign that you have not turned your compost heap in a while! Regularly mixing your heap with a garden fork will help discourage any nesting behaviours and mixing the carbon rich and nitrogen rich ingredients will also help make better compost. Turning the heap will also help it to break down faster. Disrupting the safe harbour that the rats have been enjoying has proven to be as effective as non-organic rat poisoning methods in ridding yourself of the problem.