Skip to content

Latest commit

 

History

History
205 lines (134 loc) · 3.81 KB

1-getting-started.md

File metadata and controls

205 lines (134 loc) · 3.81 KB

Getting Started

Start a Terminal

The default terminal down the bottom has a tendency to crash, start a full screen terminal to get started.

Press alt + t to open a full sreen terminal

Hello World

We're going to build a Sinatra application, because Cloud 9 is a bit different to a normal environment we're going to need to use rackup to start our server.

Start Your Server

Sinatra is a rack application, to start a rack application we use the command rackup

rackup

missing config.ru

config.ru not found

Create Config File

To start our server we need a configuration file, we'll leave it empty for now.

# config.ru

config ru

rackup

missing run statement

Missing run or map statement

We've created the config file, but rack doesn't know which app to run. Let's tell it to run IdeaBoxApp.

# config.ru

run IdeaBoxApp
rackup

Unitialized constant IdeaBoxApp

Still no good, looks like we need to create an application called IdeaBoxApp.

Create Application file.

We're going to create a really simple Sinatra application to get started, let's create an app.rb file.

# app.rb

class IdeaBoxApp < Sinatra::Base
end

We also need to tell rack where to find that file

# config.ru 

require './app'

run IdeaBoxApp
rackup

Uniitialized constant Sinatra

IdeaBoxApp relies on Sinara so we're going to need to create a Gemfile which specifies this dependency

# Gemfile

source 'https://rubygems.org'

gem 'sinatra', require: 'sinatra/base'

And rack needs to know to load the gems

# config.ru 

require 'bundler'
Bundler.require

require './app'

run IdeaBoxApp

Now let's download those files with the bundle command.

bundle

bundle

rackup

Error: you may be using the wrong PORT & HOST for your server app

Because we're developing on Cloud9 we need to specify the server and port for the application.

rackup -p $PORT -o $IP

rackup

Let's visit the url to see our website.

doesn't know

We're so close, the server is running, but the application doesn't have any content, let's try adding a hello world.

# app.rb

class IdeaBoxApp < Sinatra::Base
  get '/' do
    'Hello, world!'
  end
end

Restart the server

In order for the changes to work, you need to reboot your rack server.

Protip: You can end the server by press ctrl+c

Hello World

hello world

Save Our Work to Github

Now it's time to save our work and update Github.

git status

You should have four unstaged files

git add Gemfile
git add Gemfile.lock
git add config.ru
git add app.rb

You can also add all file with git add -A where -A means "all unstaged files

Now we need to commit this work with a message

git commit -m "Created IdeaBox app"

And we need to push all those changes back to Github (refered to as origin)

git push origin

Github commits