Rangers survived an early scare against Ayr United to cruise into the Scottish Cup quarter-finals with a thumping 6-1 win at Somerset Park.