Rails4 adapter

The rebased, mergeable version of #72 

Thanks so much @scpike and everyone else involved.