I have simple Sinatra app.
web.rb:
require \'sinatra\'
get \'/\' do
\"Hello\"
end
Gemfile:*
As an update, here is a slightly more minimal app that I created, and confirmed to be working as of today. The thin gem was not needed, and a Procfile was not needed to get an initial working app.
Gemfile
source 'https://rubygems.org'
gem 'sinatra'
config.ru
require './app'
run Sinatra::Application
Note: The require line uses './app' instead of 'app'.
app.rb
require 'sinatra'
get '/' do
'Hello, World! Find me in app.rb'
end
If you want to use this template, you can copy it, bundle, and push the Git repo.
$ git init
$ git add .
$ git commit -m "initial sinatra app"
$ bundle
$ git add Gemfile.lock
$ git commit -m "bundle install"
$ heroku create
$ git push heroku master
$ heroku open
Here's how to create a minimal sinatra app that deploys to heroku:
app.rb:
require 'sinatra'
get '/' do
"hello world"
end
Gemfile:
source 'https://rubygems.org'
gem 'heroku'
gem 'sinatra'
gem 'thin'
config.ru:
require './app'
run Sinatra::Application
Type these commands in your command line to deploy (without the $
signs):
$ bundle install
$ git init
$ git add -f app.rb Gemfile Gemfile.lock config.ru
$ git commit -am "initial commit"
$ heroku create <my-app-name>
$ git push heroku master
Then test your app:
$ curl <my-app-name>.heroku.com
and you should see:
hello world
I have had this problem a number of times in the past, and it was all because I didn't include my config.ru file with the requiring of [app].rb & then pushing to Heroku. Even if I added it afterwards and restarted, Heroku would never pick it up.
Then remove the remote from your project folder
$ git remote rm heroku
Then recreate the app
You need a Procfile
file alongside your config.ru
to tell Heroku how to run your app. Here is the content of an example Procfile
:
web: bundle exec ruby web.rb -p $PORT
Heroku Ruby docs on Procfiles
EDIT: Here's a sample config.ru
from one of my sinatra/Heroku apps:
$:.unshift File.expand_path("../", __FILE__)
require 'rubygems'
require 'sinatra'
require './web'
run Sinatra::Application
You may need to require sinatra and rubygems for it to work.
By adding the gem 'heroku' to the Gemfile, I got it working. No Procfile needed.