Translated php into rails