The ranged spell attack can be made when you cast the spell.
Produce flame says (emphasis mine):
You can also attack with the flame, although doing so ends the spell. When you cast this spell, or as an action on a later turn, you can hurl the flame at a creature within 30 feet of you. Make a ranged spell attack. On a hit, the target takes 1d8 fire damage.
So you use the ready action to hold the spell, then use your reaction to release the spell in response to the trigger – this is “when you cast the spell”. At this time you would make a ranged spell attack.