Coding challenge in ROR and PostgreDQL