I usually have a few stock encounters in mind for when my players go in a direction I didn't plan. That way it buys me enough time to prepare what comes next. Before they get to the nearby ruins they heard about in the marketplace, they come across a brigand camp or stumble upon an owlbear cave or encounter a couple hippogriffs out hunting -- since the rumor about the ruins was just something I tossed out for flavor, intending for them to follow up some leads on court intrigue I've been building up. But if they want to do a dungeoncrawl in the ruins, then that's what I'm going to give them.
I also always keep several options open. And I keep a stack of published adventures on hand to adapt and steal bits from as needed.
My play style is to dangle mutliple hooks in front of the players and let them pick which ones they want to go after. I keep a handful of adventures in mind so I can quickly prepare for whichever direction they choose -- at any crossroads I'lll know vaguely what lies in each direction and have a few "random" encounters planned so I can deal with whatever the players decide to do. Of course, at a crossroads with 3 choices they're just as likely to set off across the open field and ignore the road altogether and create a 4th choice I never anticipated.
My biggest challenge is, once they choose a direction, I have to quickly run ahead of them to build some scenery along that path so that they feel that this is the adventure I've been developing all along, while in reality I could very well be just a few steps ahead of them.
When the session is over, I have enough time before the next session to more fully develop the adventure and tie it all back in to the metaplot. And I always stay flexible enough to tie their choices back into the metastory. If all roads lead to Rome, I like to offer my players the opportunity to pick whichever road they want to take.