ga('create', 'UA-83875340-1', 'auto'); ga('send', 'pageview');
</script>This page is intended to provide all the command line instructions you need to get an app up and running on Heroku using the following technologies:
- Ruby
- Sinatra / Rack
- Capybara
- Postgresql
- Heroku
mkdir <project-name>
--> create a directory for your projectcd <project-name>
--> switch into that directorygit init
--> initialize the directory to use gitgem install bundler
--> skip this step if you already have bundlerbundle init
--> will create a Gemfile
- In the Gemfile add the following:
ruby '2.3.0' #or whatever version of ruby you want to use
gem 'rspec'
gem 'sinatra'
gem 'rake'
bundle
--> run bundle to get all the gems
rspec-sinatra init --app MyApp ./app/app.rb
--> where MyApp == name of your app and the path points to the correct folder. Don't worry about overwriting the spec_helper.rb file ... you should also see aconfig.ru
file with something like the following:
require 'rubygems'
require File.join(File.dirname(__FILE__), 'app/app.rb')
run MyApp
rackup
and go tolocalhost:9292
in your browser --> check Sinatra is working properly. You may need to use a different port - check the logs to make sure it's correct.
psql
--> launch postgresql from the command linecreate database "YourDataBase_test"
--> create a database for your test environmentcreate database "YourDataBase_development"
--> create a database for your development environment- Add the following gems to your Gemfile:
gem 'data_mapper'
gem 'dm-postgres-adapter'
gem 'database_cleaner'
gem 'pg'
bundle
--> to get the gems you just specifiedtouch data_mapper_setup.rb
--> let's create a file to load up DataMapper- add the following to the file you just created:
require 'data_mapper'
require 'dm-postgres-adapter'
# later you'll need to require the models that are using DM to connect to your DB
DataMapper.setup(:default, ENV['DATABASE_URL'] || "postgres://localhost/YourDataBase_#{ENV['RACK_ENV']}")
DataMapper::Logger.new($stdout, :debug)
DataMapper.finalize
DataMapper.auto_upgrade!
Don't forget to point at the right DB path you just created in step 11. And add require_relative 'data_mapper_setup'
to your app.rb
file.
-
Make sure your are correctly set up for different environments. You should see something like
ENV['RACK_ENV'] = 'test'
in yourspec_helper.rb
file. Don't forget to require the relevant files. In yourapp.rb
file addENV["RACK_ENV"] ||= "development"
--> that makes sure that you run the development environment by default. -
Add
require 'database_cleaner'
to your spec_helper. And the following code afterRSpec.configure do |config|
:
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
# Everything in this block runs once before each individual test
config.before(:each) do
DatabaseCleaner.start
end
# Everything in this block runs once after each individual test
config.after(:each) do
DatabaseCleaner.clean
end
This will clean out your test DB after each Rspec run ...
- At this point you should create some simply models and verify that DataMapper is working correctly and storing things in your DB.
heroku create YourApp
--> to create an app on Heroku (if you leave out YourApp it will simply pick a name at random)git remote -v
--> to verify that it has added Heroku as a remoteheroku addons:create heroku-postgresql:hobby-dev
--> to create a Postgresql DB on Herokugit push heroku master
--> you can also usegit push heroku your-branch:master
to push a specific branch to Heroku masterheroku open
--> launches your app in a web browserheroku logs
--> to see what's going on (skip this step if it's all working!)
touch Rakefile
--> create one if you don't already have once- Add this code to it:
require 'data_mapper'
require './app/app.rb' # make sure you use the right path to your app
namespace :db do
desc "Non destructive upgrade"
task :auto_upgrade do
DataMapper.auto_upgrade!
puts "Auto-upgrade complete (no data loss)"
end
desc "Destructive upgrade"
task :auto_migrate do
DataMapper.auto_migrate!
puts "Auto-migrate complete (data was lost)"
end
end
- Then run
rake db:auto_upgrade
for your local development DB andheroku run rake db:auto_upgrade