In my experience, a lot of this comes down to the basics. Moderation, balanced diet, weightlifting/exercise, and calories in vs. out.
If you eat fewer calories than you expend, you WILL lose weight.
If you were to eat only protein and fat, no carbs (or sugar, God forbid), but ate more calories than you expend, you WILL gain weight. Calories in vs. out
If you only ate jelly beans but ate fewer calories than you expend, you WILL lose weight. But you'll feel terrible. Balance.
If you ate a balanced diet, making sure to get adequate protein (at 1g/lb per day) at a calorie surplus and you add weightlifting, you gain weight in the form of muscle. Keep in mind that 1 gram of protein per pound of bodyweight per day will not reach your caloric daily expenditure for most people. Hint hint. CARBS. Some jelly beans or a slice of pizza thrown in with your fruits and vegetables (which both contain sugar, btw) will not be the cause of your death. Moderation
Eating a Little Caesar's Hot N Ready for dinner by yourself every day and not exercising almost certainly will.
If you don't want to track calories, just make sure you exercise a few times a week.