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 'sinatra' | |
class Foo < Sinatra::Base | |
get '/' do | |
"Hello, world!" | |
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
In 1.8 proc == lambda && proc != Proc.new | |
In 1.9 proc == Proc.new && proc != lambda |
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
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: | |
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
# 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. |
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
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) |
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 'sinatra' | |
enable :sessions | |
before do | |
session[:mine] ||= 0 | |
end | |
get '/foo' do | |
(session[:mine] += 1).to_s |
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
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 |
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
Test::Unit::TestCase.send :include, Sinatra::Test | |
class Waste < Sinatra::Base | |
get '/' do | |
puts session[:test] | |
end | |
end | |
describe 'Waste' do | |
before do |
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 'sinatra' | |
class Blog < Sinatra::Default | |
get '/' do | |
.. | |
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
require "sinatra" | |
post "/foo" do | |
redirect "/bar" | |
end | |
get "/bar" do | |
"Hello, World!" | |
end |