Backend I started my app by firstly creating two folders: /backend end /frontend. In the backend folder, I created a new Rails app using the --api flag. Then I have generated two resources: Top and Option. After that anytime I needed information or a change on the backend I was creating a new Controller action that was completing any request.

Frontend This part is the longest as all the JS file are here. I have started with a DOMContentLoaded event that is making a fetch request to the Top index action to get all the tops from the database. Creating HTML from the collected information from the database required two Javascript classes ( same as ruby models ) Top and Option. Both classes have a static method that takes as an argument an array of instances and uses and instance method that creates the HTML which will append to the main div (tops) or to the next sibling (option).

Code Refactoring After all the features were ready to use I end up with three long Javascript files. I noticed that fetch calls, methods that include the word “vote” as well as Notice/Errors messages was repeating.

That was not a DRY code. I have implemented another three Javascript classes”:

Share this project:

Updates