Rails 4.1 Support

Tests all successfully run with Rail 4.1.2. Started with rails-4-1-0 branch and rebased it all on the latest master.

The commit messages should pretty well document why changes were made.