[V4] Rails 3.2 minimal porting

Rebased #469.