[V4] Rails 3.0 porting

Rebased #305.