Skip to content

Instantly share code, notes, and snippets.

@drio
Created July 26, 2009 17:08
Show Gist options
  • Save drio/155860 to your computer and use it in GitHub Desktop.
Save drio/155860 to your computer and use it in GitHub Desktop.
require 'sinatra/base'
require 'sequel'
require 'scaffolding_extensions'
DB = Sequel.connect('sqlite://sca.db')
class SeqEvent < Sequel::Model(:seq_events)
end
# Change some basic behaviour in sinatra
class Sinatra::Base
set(:appfile=>'giftsmas.rb', :views=>'views')
enable :sessions, :static
disable :run
not_found do
render(:erb, "<h3>The page you are looking for does not exist.</h3>")
end
error do
e = request.env['sinatra.error']
puts e.message
e.backtrace.each{|x| puts x}
render(:erb, "<h3>Oops, an error occurred.</h3>")
end
end
# My sinatra app
class MyApp < Sinatra::Base
get '/' do
'Hello world!'
end
end
# Setup some scaffolding code for the seqeven table
class Scaf < Sinatra::Base
scaffold_all_models
#scaffold SeqEvent
end
# Link against Rack
drd_app = Rack::Builder.app do
map "/" do
run MyApp
end
map "/manage" do
run Scaf
end
end
puts "--> starting the show ..."
Rack::Handler.get('thin').run(drd_app, :Host=>'0.0.0.0', :Port=>4567) do |server|
trap(:INT) do
server.stop
puts "\n== Sinatra has ended his set (crowd applauds)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment