[V22] Rails 3.0 porting

rebased #493.