- Construct a Rails API background
- Separate frontend concerns between and index.js file and Model/Adapter files
Constructing a backend API using rails is actually rather easy. By running the command `rails new ` with the ` — api` flag attached to it automatically sets up our rails application to be used as an api. Our cors file dictates where we allow requests to come in from, as well as what types of requests are allowed.
From here, it’s simply a matter of setting up your controller actions to expect as well as return json responses.
The frontend, however, was not so cut and dry. Ultimately, there is one index.js file that dictates the control flow of the application. The destination.js and activity.js files establish class models that allow us to interact with the database. The destinationAdapter.js and activityAdapter.js are in charge of coordinating all of the fetch requests.
One thing that I did to assist in my unique application was create the dateParser class. This class allowed me to easily take date input data (in the format of
yyyy/mm/dd) and to return a more readable date.
I added a slew of customized event listeners to handle all clicks and update the DOM without refreshing the page. The index.js houses this functionality.
If you would like to explore this application more: