Support Rails 3.1+

There is another pull request for Rails 4.x support, but this change would be better as it will maintain the gems compatibility with older versions of rails as well.