[verb (dictionary form)] + ままに [verb た-form] + ままに [verb (passive)] + (が)ままに [noun] + の + ままに
ままに means doing something the way someone else's words, your own feelings, or chance lead you, without putting up resistance or judgment of your own. It follows a verb in the dictionary form or the た-form, or a noun with の.
With a verb of moving or feeling, ままに means drifting with it: wherever your feet, the wind or your mood take you. Set phrases are あし足のむく向くままに and きのむくままに気の向くままに.
With a passive verb, ままに means giving in to someone without question. The version with が, されるがままに, stresses being helpless.
ままに is written and a little literary; in conversation, いわれた言われたとおりに or すきなように好きなように is more usual. The plain まま, "with something left as it is", is a separate point: まど窓をあけた開けたままねた寝た is "I slept with the window open".