I prefer to understand this question in terms of the electric fields. Basically, Snell's law falls out of forcing phase matching at the interface.
First of all, when you talk of a light ray, I'll take that to mean a plane wave of a specific frequency and direction. Consider the problem of a plane wave approaching an interface at $x=0$ from the $-x$ half-space, so traveling generally in the $+x$ direction, but at an angle $\theta_1$ from normal. The left half-space, $x<0$ contains a material of refractive index $n_1$, and the right half-space contains a material of refractive index $n_2$. We'll assume that the electric field is polarized in the $z$-direction, and only consider the $z$-component of the electric field. This electric field can be given by
$E_1(x,y) = \cos(k_1 x \cos(\theta_1) + k_1 y \sin(\theta_1) - \omega t) \hspace{1cm} x \lt 0$$E_1(x,y,t) = \cos(k_1 x \cos(\theta_1) + k_1 y \sin(\theta_1) - \omega t) \hspace{1cm} x \lt 0$
where $\omega = 2\pi f$ is the radial frequency, $k_1 = \frac{\omega n_1}{c}$ is the propagation constant in that medium, and $c$ is the speed of light.
In the right half-space, $x>0$, the transmitted wave will look like
$E_2(x,y) = A \cos(k_2 x \cos(\theta_2) + k_2 y \sin(\theta_2) - \omega t + \phi) \hspace{1cm} x\gt 0$$E_2(x,y,t) = A \cos(k_2 x \cos(\theta_2) + k_2 y \sin(\theta_2) - \omega t + \phi) \hspace{1cm} x\gt 0$
where $k_2 = \frac{\omega n_2}{c}$ and and $\theta_2$ is the unknown transmitted angle. $A$ is an as-yet-unknown magnitude, $\phi$ is some unknown phase offset. $A$ and $\phi$ are only included to be complete, as we will quickly find that $A=1$ and $\phi=0$.
One of the first things you learn in introductory electromagnetics is that the tangential component of the electric field must be continuous everywhere, even across material discontinuities. (Unless there's some kind of source, which we're assuming there's not.) The z-component of $\mathbf{E}$ is clearly tangential to the interface. That means that we must find that
$E_1(x,y)|_{x=0} = E_2(x,y)|_{x=0}$$E_1(x,y,t)|_{x=0} = E_2(x,y,t)|_{x=0}$
$\cos(k_1 y \sin(\theta_1) - \omega t) = A \cos(k_2 y \sin(\theta_2) - \omega t + \phi)$
It should be apparent that the left and right side of this equation can only be equal for all $y$ and $t$ if $A=1$, $\phi=0$, and
$k_1 \sin(\theta_1) = k_2 \sin(\theta_2)$
$\frac{\omega n_1}{c} \sin(\theta_1) = \frac{\omega n_2}{c} \sin(\theta_2)$
$n_1 \sin(\theta_1) = n_2 \sin(\theta_2)$
This figure shows a graphical depiction when $n_1 < n_2$. Note that the fields match at $x=0$.