Fix rails version detection

The check for deprecated versions of Rails was flawed. Use `Gem::Version` to check instead, and update the other version checks to use it too.