On Heroku Cloud
1. Ruby, Rail
Ruby is an Object-Oriented Programming scripting language and Rails (the Model View Controller web app framework developed using the Ruby language). The purpose of this document is to show how to deploy a Ruby on Rails production website to Heroku cloud. This will be demonstrated via a “Thanksgiving Potluck Signup” app running on Heroku (a Platform-As-A-Service).
2. How I did it & source code
2.1. Concept of the “Thanksgiving Potluck App”
Every year, my dear friend Neil invites others and I to his house for a Thanksgiving dinner potluck. Neil usually brines and bakes a turkey, but he needs help from his guests to bring other dishes. He also wanted a way for guests to sign up for dishes, but did not want the dishes to overlap. He used Evite to manage the email list and track who is coming, but tracking who was bringing what dishes was not easy to use. And being able to access the list via web or mobile web instantly via its own URI will make the app much easier to use.
Figure 1 Thanksgiving Potluck at Neil's
2.2. Development environment
My development was on Cloud9 cloud IDE, which basically allowed me to use my browser to development and run my Rails web app. It was easy enough to use, so I gave up using a Linux terminal and my trusty vi editor. Below is a screen shof of development on Cloud9 Cloud IDE
2.3. Initial data model
For Neil’s Thanksgiving potluck, Neil wanted a simple guest registration system for the guests to use to register themselves. He wanted it to be accessible on both web and mobile. For each guest, Neil wanted to know these about his guests:
1. Name of guest
2. What food is being brought by the guest
3. Total number of people coming
4. Email of the guest
Further more, Neil said that it would be nice if the registration system can check for overlap in food brought.
2.4. Initial scaffold creation using Rails
Rails is a framework that eases web app development and testing. The framework was designed to bring order to a potentially messy process of developing and testing web apps. But the framework also potentially adds extra baggage, especially for simple web apps. One way Rails eases the creation of the framework is via automated scaffold generation. A Rails scaffold creates the necessary directory structure and pre-populated files.
2.5. Seeding the database
Now that we have a web app running, the framework of what to show (guest information) and how to manage it (edit, destroy, show) is built in and ready to use. But now we would like to have data in this web app. What is the fastest way to pre-populate data into it? We can populate the web app with data by using seed.
2.6. Data migration
The data model was created using Rails and resides in the db/migrate directory as a Ruby file. But the Rails framework eventually will interact with a MySQL database. Rails has one built-in called SQLite3. In order to “migrate” the Ruby version of the data into SQLite3, the “rake db:migrate” is invoked. To double check the output of the migration into an sqlite3 file, I used SQLite Free – Datum.
2.7. Customize the User Interface View
The Rails scaffold command creates a basic look on the View. Neil wanted a bit more customization in the web app – which means changes to HTML and CSS. In Rails, HTML is produced from processing Embedded Ruby files (erb) and CSS is produced from processing Sassy CSS (SCSS) files.
s.
2.8. Validating the data model
Neil preferred that guests not bring duplicate food. He wanted the web app to warn a guest if the food to be brought was already registered. This is easily done in Rail using the “validates” concept. Neil also want to limit the number of total guests, so a limit of 4 per guest is imposed by Neil.
2.9. Route configuration
Ruby on Rails uses a Models View Control (MVC) design pattern. Which means that web app requests from users are sent to the Controller. But in Rails, before the user request is sent to the Controller, it is first routed through a Rails router.
2.10. App testing
Rails was design with test in mind. With Rails, tests are easy to write, easy to run, and offers powerful abilities for test automation.
3. Deployment to The World - Using Heroku PAAS & Git
Now that we have developed and tested our web app on my Macbook Pro, it is time to let other use it – by pushing the web app to production. Which means Neil and his guests can starting using the app from any web browser. But in order to push my Ruby on Rails environment to production, I need a way to host my Ruby on Rails application. This is where Heroku can help.
3.1. What is Git
Git is a source code revision control system. Which allows you to store your source code into a safe place – called a repository. Git in itself is a great software development tool to keep backups of your project , as well as keep revision control so that you can revert to previous version of your project. But must we use Git?
The answer is yes – because we are using Heroku to push our project to production.
3.2. Pushing to Heroku
Heroku offers Platform As A Service (PAAS) to deploy applications. In order to productize my web app, I first applied for a free Heroku account. Once established, the Linux command line can be used to control interaction with the Heroku Command Line Interface (CLI).
3.3. Differences Between Development and Production - PostgreSQL instead of SQLite
During the development of our Rails web app on my Macbook Pro, SQLite3 was the default Relational Database System (RDB) used with Ruby on Rails. SQLite3 is an embedded RDB, in contrast to MySQL – a full RDB environment. MySQL is part of Oracle, which leaves the Open Source community a bit nervous because Oracle makes money from selling its own Oracle Database.
For those looking for pure open source RDB, PostgreSQL is the popular choice. Moreover, PostgreSQL is a Object Relational Database. Hence it is not surprising that Heroku supports PostgreSQL over SQLite.
3.4. Production Web View
4. Conclusion
Ruby is an object oriented scripting language
targeted for web applications. Rails add a framework around Ruby so that
code with specification functionality has a nature home in the
framework. Rails adopt the MVC design pattern. Ruby on Rails provides a
proven and robust framework for web app development, testing, and
production. Within a few short Rails command, a full web app is
created. Heroku cloud was picked as the public cloud hosting platform.