Upgrade to Rails 4

Thanks to everyone who helped with this. Finally the tests pass so this is PR-able. Sorry, this is giant. :sunny:
Done.