DEV Community

Nathan Rymarz
Nathan Rymarz

Posted on

My First Ruby On Rails Project

Developing my first Rails app was an entertaining and productive experience. By this point I felt like I had learned enough to make an impressive website and I was eager to prove it. I wanted my app to be something a layperson might view as more than just a student's project. The idea I had was an app that uses Twitch.tv's API to grab random streams and display them to my users. Users can find new streams to watch by refreshing the page. Moreover, once they find a stream they like, users can also post channel recommendations for others on the site to see.

Starting out, I wasn't sure how to use twitch's API or if I would even be able to embed streams. Reading Twitch's documentation on their API cleared some things up but I still had to figure out how make requests. Luckily, there's a gem, 'twitch-api', that makes calls to the API in ruby code which made things much easier. Unfortunately, the only thing the gem couldn't do was make a request to get an app-access token, which is necessary for embedding streams. However, after some googling and tinkering around with ruby's URI and NET::HTTP classes I was able to make a post request to twitch to ask for an app token. Now I was in business to get the real guts of my app.

Creating the database, models, controllers and views was straightforward. I managed to build out the foundation of my app with all the CRUD features with relative ease. One issue that I ran across was related to instantiating new instances of the Channel Model when users created recommendations. When users specify the channel name in their recommendation I wanted my app to find or create the related channel. To do this I made a method find_or_create_by_name in my Channel model. Yet, instead of finding the related channel when one existed, it always created a new one. I figured out that this happened because of a difference of capital letters between the user-specified channel names and the channel names that were provided by the API. To fix this, I altered the find_or_create_by_name method to call the API first and find the channel with the user-specified name. Then I used the name retrieved from the API to see if there was a Channel in my database that matched. Although this was a minor issue and didn't take much time to solve, I was contented to learn a lesson about not assuming that ActiveRecord will always know what you want and to not forget about small things like capital letters that can make a big difference in the validity of data being saved into a database.

After finishing everything on the back-end, the last thing to do was give my app a professional look. Being inexperienced with CSS I spent some time searching about the easiest way to go about doing this. I learned about bootstrap and spent a while reading about how to use it. Once I got the basic feel for it, I spent the entirety of the next day styling my website. Using bootstrap made a world of difference in the enjoyability of styling to me. Now I'm looking forward to doing it again on my next project.

Although I wasn't sure how much I would be able to accomplish at the start, I'm happy to say that my project turned out better than I expected. Using API's, building the back-end of my app with Rails, and lastly styling the views with bootstrap made me feel like I was a professional, building an app for a customer. I enjoyed creating my first real Rails project and I'm looking forward to getting to do this professionally.

Website Picture

Top comments (0)