Created
January 30, 2009 05:27
-
-
Save kematzy/54948 to your computer and use it in GitHub Desktop.
This file contains 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
# 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 | |
This file contains 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' | |
### 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 ) | |
This file contains 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/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