No, on earth, gravity still plays a part. However, how much a railgun and it's projectile is affected by gravity is in direct relation to how much energy you use to hurl the projectile.
Lots of energy = little affection by gravity
Little energy = lots of affection by gravity
And, we have atmospheric drag affecting the projectile, that is, hitting the air slows it down.
If you were to fire a railgun into empty space however, with no planets around to affect it with gravity, and of course no air to
produce friction, your theoretical maximum length is near endless. The kinetic energy of the round will decrease ever so little each nanosecond, and eventually the projectile will come to a halt, unless it hit something before that. Such as Jupiter or Uranus.
A laser however, that has to physical mass to be affected by drag etc., will keep going until it hits something.
edit
A laser in space that is.