2. Setting up staging environment (render)

Now that we've set up our project, let's also set up GitHub so that we can save our project online and go back to previous versions when we want to.

First, we have to set up our SSH keys. Follow this guide to do so. Follow each step in the guide from "Checking for existing SSH keys" to "Testing your SSH connection".

image.png

After you've completed everything in that link, open up a second terminal window. You should now have 2 terminal windows open. One terminal window should be running the rails server.

Having Two Terminal Windows Open

We want to have two terminal windows open. This is because we want one for running the server and one for typing in rails commands.

You can create a new terminal window in C9 like this:

image.png

One terminal will look like this, where you can type in commands:

image.png

We also need another terminal window for running the server:

image.png

You'll notice that the terminal window that is running the server will not respond to anything that you type in. You can only execute commands in terminal windows that don't have a server running on it (the terminal window in the first screenshot).

In the terminal window for running commands, let's run the following command:

git init .

It should give you a message like this in the terminal:

Initialized empty Git repository in /home/ubuntu/workspace/.git/

Next, let's run the following commands:

git add .
git commit -am "Initial commit"

Now let's go into GitHub's front page and create a new repository. On the left-hand side, you should see a green button called "New".

image.png

Click on that button and just fill in the box that says "Repository name".

image.png

Make sure you don't check any inside "Initialize this repository with:"

Now click Create repository.

On the next page, go to the sections that says "…or push an existing repository from the command line".

Copy the code right beneath that and paste it into your terminal. It should look something like this:

git remote add origin git@github.com:YourGithubUsername/ideator.git
git push -u origin master

Make sure you replace git@github.com:YourGithubUsername/ideator.git with your username.

When you run this command, it might ask you for your username and password. If it does, then enter your Github username and Github password.

Once you are done with this process, let's make sure that everything is setup correctly. In your terminal, run the following command:

git remote -v

In your terminal window, the following lines should be outputted:

origin  git@github.com:YourGithubUsername/ideator.git (fetch)
origin  git@github.com:YourGithubUsername/ideator.git (push)

If nothing is outputted, then chances are that you missed a step. Try following every step carefully and make sure not to make typos.

You're all set! Your GitHub is set up and ready to go!

Setting Up Render

Render is used to deploy a variety of applications and services, including static websites, dynamic web apps, and more. It makes deploying our application as easy as pushing out code to source control.

First, go to Render and create a new Render account. You can sign also sign in using gmail or github

Next, create a file named render-build.sh in your repo's bin directory. Paste the following into it and save:

#!/usr/bin/env bash

set -o errexit

bundle install
bin/rails assets:precompile
bin/rails assets:clean

bin/rails db:migrate

Make sure the script is executable:

chmod a+x bin/render-build.sh

Commit and push your changes to your Git provider.

Deploy On Render

To deploy your app on Render, we'll create two services.

Create your database

Connect to your database

image.png

Connect to your Render serivces

PROPERTY VALUE
Language Ruby
Region Select the same region as your database
Build Command bin/render-build.sh
Start Command bin/rails server
KEY VALUE
WEB_CONCURRENCY Set the default value provided
RAILS_MASTER_KEY Paste the contents of your app's config/master.key file.
DATABASE_URL The internal database URL for the database you created above

Screenshot From 2025-07-10 12-49-28.png

Now if you go the dashboard of render you will see the status deployed for your service name. Congratulations, you've deployed your first Rails application!

Lesson list