Skip to content

Instantly share code, notes, and snippets.

View vangberg's full-sized avatar

Harry Vangberg vangberg

View GitHub Profile
require 'sinatra'
class Foo < Sinatra::Base
get '/' do
"Hello, world!"
end
end
@vangberg
vangberg / README
Created February 18, 2009 10:32
lambda v proc v Proc.new
In 1.8 proc == lambda && proc != Proc.new
In 1.9 proc == Proc.new && proc != lambda
If only one of the text fields are filled in the params will look like this:
{"foo" => "bar"}
While it looks like this if both are filled in:
{"foo" => ["bar", "baz"]}
And really, in the first case it *should* be:
@vangberg
vangberg / README
Created February 22, 2009 01:06
Deploying a Sinatra app to Heroku
# Deploying a Sinatra app to Heroku
## Database
The location of the database Heroku provides can be found in the environment
variable DATABASE_URL. Check the configure-block of toodeloo.rb for an example
on how to use this.
## Server
Heroku is serving your apps with thin, with means you have all your thin goodness available,
such as EventMachine.
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 1d0cbe6..46d9d7b 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -49,7 +49,7 @@ module Sinatra
else
body = @body || []
body = [body] if body.respond_to? :to_str
- if header["Content-Length"].nil? && body.respond_to?(:to_ary)
+ if body.respond_to?(:to_ary)
require 'sinatra'
enable :sessions
before do
session[:mine] ||= 0
end
get '/foo' do
(session[:mine] += 1).to_s
class MockSocket
def self.pipe
socket1, socket2 = new, new
socket1.in, socket2.out = IO.pipe
socket2.in, socket1.out = IO.pipe
[socket1, socket2]
end
attr_accessor :in, :out
def gets() @in.gets end
Test::Unit::TestCase.send :include, Sinatra::Test
class Waste < Sinatra::Base
get '/' do
puts session[:test]
end
end
describe 'Waste' do
before do
require 'sinatra'
class Blog < Sinatra::Default
get '/' do
..
end
end
require "sinatra"
post "/foo" do
redirect "/bar"
end
get "/bar" do
"Hello, World!"
end