Adding Postgres and ActiveRecord
Getting started - adding dependencies to your project
Guides, tutorials and labs to accompany CMU's Programming for Online Prototypes (49-714).
Everything you need to know about building microservices for the web with Ruby and Sinatra.
In this step, you will prepare a simple project repository with GitHub that can be deployed to Heroku.
To work with Heroku, we’ll need to create a fresh application directory (remember every project should have it’s own directory.) And we’ll need to add this application to a git repository that we can use to push our application to the Heroku server.
In order to deploy your application, we need to be able to track versions. Why? This makes sure that the current and correct version of the code is deployed to the server but also gives you the ability to rollback changes if ever anything should go wrong.
First, we need to create a tracked Git repository on our local computer. To do this, open Github Desktop, and click the File
Menu and the option for New Repository
. Browse to the location where you want to store your project and name the folder appropriately. (Tip: you’ll probably want to store all your webapps in one place). Give the folder a good memorable and descriptive name without spaces (underscores and hypens are A.O.K.). (Tip: renaming a repo is a little messy so try to give your folder a good name up front.)
This has created a Git-tracked project, we just need all our project assets to live in this folder. Copy over any basic project files you’ll need for your project (e.g. a Gemfile, an app.rb, etc. etc. ). Don’t forget to clean them up (Tip: If you’re copying from an existing project clean out any migrations, schemas in your db folder; open your Gemfile and remove all but the basic required gems, and only leave a root/main endpoint in your project!) You should have at minimum a Gemfile
and a app.rb
ProTip: Don’t forget to bundle install
to add the required files to your project. And test that it runs without any errors before proceeding!
You should see something like the above. All of the files you added are bundled up into a single commit to the repository. Let’s make the repo live. Push the Publish
button on the top right. This will sync the repo with Github.com
This will ask you to add a little basic information to your account. There’s also the option to keep the repo private. If you choose public, your project, it’s history and any changes will be publicly visible to any one who visits your github user page. Tip: You get a free educational discount on GitHub. It’s quick and easy to apply for and this gives you a basic plan for Zero Dollars. With that, you get unlimited free private repositories.
Push publish. Give it a minute and visit your account on Github.com and you’ll see your new repository listed.
Great. You now have a functioning git repository that contains a simple application.
We need to start to add a few things to get it working with Heroku
We’ve essentially created a new Ruby project folder.
You’ll need to install the gems. Use bundle install
to do this in the command line. Test your project by starting it with ruby app.rb
and make sure everything works.
Once you’ve made these changes: do another git commit and sync the changes to github.com