Watch ye and pray, lest ye enter into temptation. The spirit truly [is] ready, but the flesh [is] weak.
Note 7 at Mr 14:38: Matthew, Mark, and Luke all recorded Jesus' admonition to His disciples to pray. Matthew's and Luke's wording (Mt 26:41 and Lu 22:40) could be interpreted to mean that Jesus was instructing His disciples to ask the Father to keep them from being tempted. However, the way that Mark recorded Jesus' words (also Lu 22:46) leaves no doubt that He was saying that if the disciples were communing with the Father through prayer, they would not be tempted.
Temptation is linked directly to what we think upon (Heb 11:15). Temptation has to be entered into. We can avoid temptation by avoiding thinking on things that engender temptation (Pr 23:7). Since there is no such thing as not thinking, we cannot just try to reject all the negative thoughts of this world; we must also think on the positive truths of God. This is where prayer comes in.
In prayer, we have our minds stayed upon God and therefore are not receptive to the thoughts that conceive temptation (Isa 26:3 and Php 4:8). Temptation or sin must be conceived (Jas 1:14-15). Just as the easiest way to avoid an unwanted birth in the physical realm is to avoid conception, so in the spiritual realm, it is easier to avoid being tempted by being in constant communion with God than it is to overcome temptation once it has been conceived.