transfer the code from rails 3 to rails 4