mostly convert python to rails