If you plan to have a prolonged stay in the gym or plan an exercise regime that will surpass 1-2 hours then it’s best you eat before exercising. This will enable your body use up the calories as it keeps us with prolonged activity. It will also reduce the rate of cortisol production. Oats meal (any healthy carbs meal) is best if you are just loosing weight alone but a high protein meal will aid gaining muscle.
If your plan is to exercise for less than an hour, then exercise before eating.
Same factors as above govern the choice of meal.