require "sinatra/base" class RackApp < Sinatra::Base use_in_file_templates! get "/" do erb :home end get "/go" do erb :go end get "/internal_redirect" do redirect "/" end get "/external_redirect" do redirect "http://google.com" end get "/absolute_redirect" do redirect URI.join(request.url, "foo").to_s end get "/foo" do "spam" end post "/go" do @user = params[:name] @email = params[:email] erb :hello end get "/upload" do erb :uploader end post "/upload" do uploaded_file = params[:uploaded_file] Marshal.dump(:tempfile => uploaded_file[:tempfile].read, :type => uploaded_file[:type], :filename => uploaded_file[:filename]) end get "/error" do ["Exception caught: you wanted it."] end end __END__ @@ layout
visit there
@@ go @@ helloHello, <%= @user %>
Your email is: <%= @email %>
@@ uploader