Skip to content

Instantly share code, notes, and snippets.

@raws
Created October 21, 2010 21:43
Show Gist options
  • Save raws/639419 to your computer and use it in GitHub Desktop.
Save raws/639419 to your computer and use it in GitHub Desktop.
Simple Sinatra-based Ruby web application
require "rubygems"
require "sinatra"
require "sequel"
@db = Sequel.connect(ENV["DATABASE_URL"]) # Provided by Heroku
@db.create_table? :names do
primary_key :id
String :name
end
@names = @db[:names]
get "/" do
"Hello world!"
end
get "/:name" do |name|
if @names.first(:name => name)
"Naff off, #{name}!"
else
@names.insert(:name => name)
"Hello, #{name}!"
end
end
# Standard "Rackup" file which tells Heroku how to load this Rack-based application
require "application"
run Sinatra::Application
source :rubygems
gem "sinatra"
gem "sequel"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment