My First Ruby on Rails App

Getting started

After attending the Flatiron Software Engineering Bootcamp for nearly 6 months, I thought I had a good grasp of the ruby language. After wrapping up the third phase on Ruby on Rails and starting my first rails app, all of my knowledge was truly challenged. There were so many moving parts; if one component doesn’t get configured correctly, the entire app will not work. This was my life for the past two weeks — troubleshooting like never before. The requirements were extensive but they were also a great guide for implementation. Here were the requirements:

  1. Done in Ruby on Rails.
  2. Models include belongs_to, has_many, and has_many :through.
  3. Models have validations.
  4. Include class level scope method.
  5. Standard authentication: login, logout, signup.
  6. Third party authentication using Omniauth (in this case I used Github).
  7. Nested resources.
  8. Validation errors display correctly.
  9. Application must be Don’t Repeat Yourself (DRY).
  10. No scaffolding as there would be no learning if code is done for me.

Finding the Right Project

After spending some time reviewing the requirements, I took a step back to think about what I’d want my app to be about. I figured, there are enough social media sites out there, but I didn’t find a suitable one where, instead of posting photos or comments, one can express themselves through Haikus. A Haiku is a form of poetry that I’m very fond of. It is short, sweet, and straight to the point, while simultaneously being vague and intriguing. A Haiku always has the same amount of syllables (17) as that is its signature characteristic. So I thought it would be a fun experience to make an app that showcases a user’s haikus through HaikuMe.

Setting Up

Rails is such a massive environment that it felt overwhelming thinking about where to start. Thankfully, rails contains many useful functions. One of my favorites is the rails generator command. While the generators can help, only some generators were allowed to be used like models, migrations, and controllers. This allowed me to make all the necessary templates needed for my app and avoid some misconfigurations.

App Configuration

My app is comprised of the following classes interacting with each other:

  1. User: Has username and password. Can Signup, log in and create Haikus.
  2. Haiku: Has a title, three lines with different amounts of syllables, and themes.
  3. Theme: Has a title.
  4. Session: Stores user session data.

After getting the backbone of my classes together, it was time to start the implementation.

App Implementation

Before implementing sessions and users, I made sure I could even build a Haiku in the first place. While creating an HTML form to make a new haiku, I acknowledged that the form could also be used to edit. This is helpful because it makes refactoring easier and keeps things DRY. The form also includes error messages for both actions (creation and modification) without additional files.

Then, upon firing up the rails server, and adding a few “binding.pry” to troubleshoot in different places, I was able to make a haiku and save it to the sqlite3 database. Now, it was time to add the user functionality. This depends on the users’ controller working together with the sessions’ controller. In order to do this, I built a standard authentication scheme using bcrypt for secure passwords. This portion was straightforward since it was similar to authentication in Sinatra. My application’s login page could also authenticate using omniauth.. This was the true challenge for me.

Omniauth

Implementing omniauth into my app is the process that took the longest amount of time. From the routes not being set up correctly to not being able to redirect to the third party service, omniauth tested my knowledge, patience, and resourcefulness. Configuring omniauth was truly a learning experience because it forced me out of my comfort zone. My existing knowledge from the bootcamp was not enough; I had to forage through documentation and online tutorials and spend long nights testing and troubleshooting. In the end, I was able to develop a working prototype that allows users to sign up with HaikuMe using Github.

Software Engineering Student