I built my first web application! That other people can log into and use! Our project’s requirement was to build a web application using Sinatra as our Framework. I felt like a baby taking their first steps on their own. I was slow and wobbly, but with my earnest attitude I persisted.
My application is named My Book Collection. With My Book Collection you can view all of your books in one application. If you’re anything like me, you have books in different places. I have books in my living room, in my bedroom, and even at my friends’ houses. It can be tough to keep track of where all my books are, especially if I loaned them to a friend. You can view all of your books on a single page with My Book Collection and click on a book to review the book’s status (if it’s on loan, read, unread etc), as well as the book’s author and genre.
Before I started coding, I wrote out user stories in my journal. How I expected the app to function, what I wanted the app to accomplish etc. This gave me a clear vision and limited the decision making I had to make while coding. Specifically, I only wanted users to interact with the app if they were logged in. Similarly, I knew I wanted users to have the capability to edit their own book collection.
How to deploy an app on Heroku.
Heroku is a platform where users can deploy their web applications on the web so other people can use it. It took some time to successfully connect my GithHub account with Heroku. When I use a new platform I tend to take the process very slowly to ensure I’m not just mimicking steps but rather understand the process. I envision myself using Heroku for many projects in the future, so understanding how to upload a web application this time around is helped out my future self.
Taste of Ux/UI.
Although my main focus with this project was to understand the backend and how my objects interacted with each other, I had some moments of considering the user experience of my application which was new for me. When I am working on my labs, I’m not as focused on the Ux because my name isn’t tied to the project. However, My Book Collection is completely my own! For example, initially, I had a delete button too close to the edit button. I imagine users will want to edit their books often, it would be frustrating to delete a book when all you wanted to do was update its status! Therefore, I increased the white space between the edit and delete button.
ActiveRecord comes with many helpful methods to call on objects in order to create, read, update, and destroy objects. This documentation here https://guides.rubyonrails.org/active_record_basics.html was a great reference. I ran the rubygem Tux so I could create and play around with objects in my terminal to test my application’s onjects to make sure they were interacting with one another correctly. Alternatively, I could have created seed data to have for my app, but I wanted to play around with ActiveRecord’s CRUD methods to get more comfortable with them since I was planning to include them in my code. The method that was the most fun to use was the .where method. Calling .where on an object is the SQL equivalent to saying:
Select * from table where column_name = 'condition'
This was helpful because I only wanted users only see their own books. I then added the .each method in order to iterate over each book so it could be listed separately on the user’s page.
<h1>Here are all of your books:</h1> <%Book.where(user_id: current_user.id).each do |book|%> <ul> <li>Title: <a href="books/<%=book.id%>"><%=book.title%></a> <p>Author: <%=book.author%><br> Genre: <%=book.genre%></p> </li> </ul> <%end%>
Don’t be intimidated by errors.
The instructors at Flatiron try to reinforce the fact that most of the time code is going to be broken. For the most part, I’ve embraced this and this mentality helps when other things besides code aren’t working projects. For example, I ran into an error with Shotgun, which is a RubyGem that let’s you run your application on your local server and updates changes you make in your code in real time, so you don’t have to stop, code, save, and run the application.
The error caused my browser to look like this:
This was in my terminal:
Set SINATRA_ACTIVESUPPORT_WARNING=false in the environment to hide this warning. objc: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called. objc: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
Luckily, I googled my error and found that other people had the same issue and there was a Issue thread on Shotgun’s GitHub repository, link here: https://github.com/rtomayko/shotgun/issues/69. I ran through all of the suggested resolutions, and ultimately I had to update my Mac’s software to Mojave and then install macOs’ Xcode which added components to get Shotgun up and running. It probably took me 3 hours to resolve this issue, between the software updates, trying out different resolutions, and talking to my fellow cohorts to see if they had any ideas. However, this experience taught me that I’m not alone with the issues I experience. There are very generous people out there who have run into the same error and decided to write about it! Also, I was proud of myself for remaining level headed and persisting in order to solve my problem.
As always, I learned a TON about ActiveRecord and Sinatra by building my app. It reinforced my foundation which is important for our next section… Rails!
P.S. here’s a walkthrough of the app!