According to Einstein theory of general relativity (published in 1915), gravity is just the consequence of the distortion of "space-time" caused by massive objects. The sun is massive enough to warp space around it. The more massive an object, the more it warps the space around it and the space distortion it causes is felt as gravity.
It is a common pedagogical approach to simulate this space warping the same way a heavy ball resting on a rubber sheet warps the sheet. But we have to be careful while considering this model since it carries a lot of misconceptions. Among them the fact that space is limited to a 2D flat universe, time seems the same everywhere which is not the case, and gravity (planets attracted by the sun) is described by itself (planets falling in the well).
Nevertheless, "All models are wrong, some are useful".