[V2] Rails 3.1 porting

New version of #300.