I've tried hot glue, sandpaper dots, all kinds of stuff, and finally developed a technique of holding the ruler down with my thumb and my pinky finger going over the edge of the ruler, and my other 3 fingers pressing down on the ruler. This worked great.
Until I discovered Steady Betty strips. Holy moly, those things are awesome. They're about a quarter inch wide and 4 inches long, and I cut one in 3 pieces and stuck it on my ruler. That sucker doesn't go ANYWHERE anymore. Of course, now I have to pick the dang thing up, I can't slide it across my fabric to make the next cut....