So, wait until the rail gun ship gets two hundred miles from your coastline, launch a cruise missle at it, and sink the ship before it fires a shot.
We actually do know how to protect our ships, and we are capable of removing threats or countering threats as we make our deployment choices. The ships with railguns are not going to be sitting ducks.
If your cruise missile makes it to the target at all.