Created
October 21, 2010 21:43
-
-
Save raws/639419 to your computer and use it in GitHub Desktop.
Simple Sinatra-based Ruby web application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Standard "Rackup" file which tells Heroku how to load this Rack-based application | |
require "application" | |
run Sinatra::Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem "sinatra" | |
gem "sequel" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment