Use code from rails 3.2.8