Converting Your First Ruby CLI App Into a Ruby on Rails Web App

Bryn Knowles
The Startup
Published in
5 min readOct 19, 2020

I have a CLI app that I created in Ruby for my first project at Flatiron School. I’m pretty proud of what I accomplished in just a couple of days. The app was built from scratch with nothing but the basic knowledge of Ruby that I learned in a little over a week. The fact that the user interface was working in time for my presentation was a huge relief. I had something to show everyone, and it brought me back to my early days of programming in a dos prompt — where my interest in coding truly began.

my first Ruby CLI app

As cute and nostalgic as my little app was, I knew I wanted to build on it someday. My goal was to give my users a more visual and interactive experience as they navigated through my text-based app. I had visions of adding more user stories, and some cool ASCII graphics with a background soundtrack of cheesy arcade music. To add more under the hood and additional flair would take a bit of time and attention — and time was not on my side while attending school. Vowing to come back to it, I put my project expansion on the back burner while Mod 2 of Flatiron got underway.

In Mod 2, I began to learn Ruby on Rails. Rails is a web application framework that is written in Ruby and provides the backend functionality of a database and a web server, as well as the front end functionality of creating web pages for the user experience. It took me some effort to understand Rails, as I clumsily tried to keep track of all the many moving parts. I at times literally felt like I was on a runaway freight train, just trying to grasp at all the information that was coming at me. Rails is actually a beast of a framework, and there is A LOT to learn. One thing that was helpful to think about is that there is a process to everything you do when you are building things in Rails. This makes it easier to break the entire process down step by step. It is also true that the more you do something, the better you get at it. I learned a great deal by making mistakes and learning how to fix them.

The brilliance of Rails is that you can see your mistakes happening directly in the web browser as you code. Having an artistic and creative background, I need to see things and to learn by doing. Rails gives me both of those qualities. I also lack patience (I’m learning how to unlearn this), so the fact that there’s just so much you can do in such a short amount of time, when creating a basic web app, is a form of instant gratification for me. I can see what I’m building in real time, which gets me super excited to build things!

win win situation

As we all know, practice makes perfect, so it wasn’t long before I realized that if I took my original Ruby app and converted it to a Rails app, I could hone my Rails skills and level up my app all at the same time! Which brings me to my process of converting my Ruby CLI app to a Ruby on Rails web app…

Admittedly I could find no documentation on this subject. I searched for quite a while and just decided to go it alone, for better or for worse. This lead me down an arduous path of trial and error, in which I made some incorrect decisions, beginning with physically trying to merge my existing Ruby app with a new Rails app in the terminal with git commands. On the plus side, I did learn how to mirror a repo, and got pretty good at creating repos from scratch. I also learned many more terminal commands, like how to move files around in my apps. All well and good but not teaching me anything useful in learning how to create this project.

face palm on an endless loop

Once I got myself back on the rails, so to speak, I realized that my process of converting was misguided (hence no documentation on the subject) and what I really needed to do was just start a new Rails app and use my Ruby app as a reference! Since the user experience would no longer be in the CLI, I didn’t need most of my old application. What I needed were the models themselves (or at least the idea of these models) and their relationships and associations with each other. I also needed to reference my database tables and my seed data. So I started from scratch, created a new Rails app and began the process of creating my models, database, routes and views.

Step By Step Process Of Creating A Basic Ruby On Rails Web App

  1. create a new git repo
  2. clone the repo down to your local machine
  3. open the repo in your text editor of choice
  4. create a new rails app (rails new <project-name>)
  5. cd into your project directory (cd <project-name>)
  6. generate a new model, controller, view folder and migration table for each of your models (rails g resource ModelName attribute_name(s):attribute_data_type(default is a string) — no-test-framework)
  7. copy/paste some of your old model code into your new models (like the associations, any extra methods you might use)
  8. check your associations in your models to make sure they still apply — edit as needed
  9. add your validation helpers to your models now, or after you write your flash hashes in your controllers and call them in your views (see 17 and 19)
  10. check the table columns and edit/delete columns as needed
  11. create some seeds for new instances of your models (I like to use the Ruby gem called faker)
  12. migrate to your database (rails db:migrate)
  13. seed your database (rails db:seed)
  14. check your schema
  15. start your server and begin testing as a user (rails s)
  16. add actions to your controllers, such as index, show, new, create, edit, update, destroy
  17. write the block of your controllers’ actions(methods) — making use of strong params, flash hashes and proper redirects
  18. add views for your controller actions (e.g. index, show, new)
  19. write your html and ruby inside of your views files — calling your flashed data, and making use of form_for, link_to, button_to, collection_select, etc., as needed
  20. check your routes and make sure they are adequate (use RESTular as a reference)
  21. test as you build these things, by calling the views in the browser and pretending you are a user
  22. when everything is functional, add some CSS to polish your UX
  23. pat yourself on the back! You just “converted” your Ruby app into a Ruby on Rails app!



Bryn Knowles
The Startup

Software Engineer // JavaScript | React Hooks | Ruby on Rails