Rails 4 compatibility fixes

A raft of changes that fix compatibility with Rails 4, mostly due to deprecations.