ついでに・がけに: the difference
ついでにN3
Meaning
While you are at it, On the occasion
Past papers
Tested 2 times in past papers
Example
ついでに君の分も払ってあげるよ。
While I am at it, I will pay for your share too.
がけにN2
Meaning
On the way to, As you go
Past papers
Example
女の子の噂話:「さっきあいつ、来がけに妙なことを言ってたね。」
Girls gossiping: 'Just now, on the way here, that dude was saying weird things.'
How to tell them apart
「途中で」 is the plain 'on the way' and goes with any verb.
「ついでに」 means doing a small thing while doing a main one, and takes many verbs and nouns: 「散歩のついでに」「買い物のついでに」.
「がけに」 is almost only used with movement verbs, stressing 'along the route'.