Skip to content

skygroundmedia/boilerplate-sinatra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boilerplate Sinatra

Boilerplate Sinatra app that includes:

  • Heroku-Ready
  • User Registration
  • Sendmail using GMail and Sendgrid
  • Warden Authentication

Step 1

Download this app

Install this codebase

Step 2

Set-up your dev environment

Make sure you're using Ruby 2.2.5. If not, review this article on how to upgrade Ruby on Mac OS X using rbenv

 ruby -v

Update gem –the package manager we're going to use.

 sudo gem update

Update all the app packages found in Gemfile.

 sudo gem install bundler 

Step 3

Install app packages

Install all the app specific packages

 bundle install --without production

Step 4

Start local webserver

Start your web server (using Procfile + Foreman )

 gem install foreman
 foreman start

Step 5

Build your app

Step 6

Configure Heroku

Install Heroku

 sudo gem install heroku

Log in to Heroku

 heroku login

If you need a local SQL database, you'll need to pick PostGres

Configure Heroku Toolbelt

Step 8

Publishing from Git to Heroku

Verify the remote git

  git remote -v 

Verfify you have an app in Heroku

  heroku apps

Link your git to Heroku

  heroku git:remote -a [name of app on heroku]

Step 9

Bundle and Lock down your Gemfile

  bundle install --without production

Publish your git code to Heroku and Github

  git push heroku master

Databasese

Managing a local DB through IRB

First register your database by finding and promoting it

 irb
 require './app'
 DataMapper.auto_migrate!

Managing a production DB through Heroku's Console

First register your database by finding and promoting it

  heroku pg
  heroku pg:promote [HEROKU_POSTGRESQL_NAME_OF_DATABASE]
  heroku run console
  require './app'
  DataMapper.auto_migrate!

Installing SQLite

Use Homebrew to install SQLite

  ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
  brew install sqlite
  gem install sqlite

Process

  1. Gemfile is used to store all the libraries and dependencies you'll need to launch and deploy your app.
  2. Procfile is the process file you used to kickstart your app.
  3. Foreman is the toolkit you use to automatically start-up your server
  4. SQLite is what you'll use for a local SQl database
  5. Postgresql is the SQL database you'll use for production
  6. config.ru is the configuration file that connect Procfile to your initial app.rb file.

Adding a new property to the Database

Add the property within the class

 property :likes, Integer, :default => 0

Use IRB to migrate the database

 bash$ irb

Use DataMapper to update the tables

 DataMapper.auto_upgrade!

Test out your work

 bash$ irb
 require './app' 
 bash$ song = Song.first
 bash$ song.likes

Double check your DB on Heroku

Run Console

 heroku run console

Upgrade DB

 require './main'
 DataMapper.auto_upgrade!

Resources

Authentication

Boilerplate Code


Errors

foreman start

Web server errors Find out if any servers are running 'headless'

 ps aux | grep ruby

Quit any 'headless' running servers

 kill -9 xxxxxx

Check Heroku logs

  heroku logs