Book Journey — JavaScript Project

Setting up the backend

Setting up the backend was relatively painless — rails has most of it already laid out for you if you use the scaffold option when creating models. My two models are: a Book model and a Recommendation model. The relationships are: books have many recommendations, and a recommendation belongs to a book. I pulled books from a few different end points of the New York Times books API and seeded the data into my database.

Dealing with the asynchronous nature of JavaScript

As I started building my webpage, I decided I wanted to list book recommendations underneath their respective books. Since JavaScript doesn’t have the same handy methods ActiveRecord does, I needed to think a bit about how to display these associations properly. I started with a method in the recommendation class to find all recommendations associated with the passed in bookId

recommendation.js
book.js
book.js
bookService.js
index.js

Sorting Books by “most-liked”

Another functionality I added to my application was the ability to sort books from most to least liked. I attached an event listener to a button, with the following callback function:

book.js

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store