Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kematzy/54948 to your computer and use it in GitHub Desktop.
Save kematzy/54948 to your computer and use it in GitHub Desktop.
# app1.rb
### APP 1 (Old Style) does work with static files in /public
require 'rubygems'
require 'sinatra'
get '/' do
"Hello world! from Sinatra v#{Sinatra::VERSION}"
# => Hello world! from Sinatra v0.9.0.4
end
require 'rubygems'
require 'sinatra'
### APP 2 (Scoped Style)
### does NOT work with static files in /public
class MyApp < Sinatra::Base
# enable :static
set :public, File.dirname(__FILE__) + '/public'
set :root, File.dirname(__FILE__)
get '/' do
"Hello world! from Sinatra v#{Sinatra::VERSION}"
# => Hello world! from Sinatra v0.9.0.4
end
end
# non-default port so that I can have two apps running
# side by side
MyApp.run!(:port => 4568 )
require 'rubygems'
require 'sinatra/base'
### APP 3 (Scoped Style)
### does work with static files in /public
class MyApp < Sinatra::Base
## need to enable static files from the public directory
enable :static, :public
## this is optional in this case
# set :root, File.dirname(__FILE__)
## this must be set or else the loading of static files from public bails with major blowup:
## ERROR:
# Read error: #<NoMethodError: undefined method `+' for true:TrueClass>
# .../sinatra/lib/sinatra/base.rb:773:in `GET (?-mix:.*[^\/]$)'
set :public, File.dirname(__FILE__) + '/public'
set :logging, true
get '/' do
"Hello world! from Sinatra v#{Sinatra::VERSION}"
# => Hello world! from Sinatra v0.9.0.4
end
end
# non-default port so that I can have two apps running
# side by side
MyApp.run!(:port => 4569 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment