Both side of the argument are valid, I learn music theory as special reliable tools but most of the best melodies just pop out in my head at random moments or in dreams and then I remake them in the DAW, theory will help you not get stuck when you're no sure where to take it next. Music theory has help a lot for chords though, and chords can inspire great melodies. Jamming along to music and getting in the zone* helps a lot to understand and learn. To know the scale of a song, simply play any song and play on the keyboard over the song or a part of a song and decide which 7 or so notes work in 1 octave, copy onto 6 octaves and you have the scale.
A lot of great musicians don't know theory or how to read music (the actually know theory but not the language):
LInk