[V15] Rails3 backporting to Rails2

Rebased #405.