Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created March 23, 2012 16:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngauthier/2172615 to your computer and use it in GitHub Desktop.
Save ngauthier/2172615 to your computer and use it in GitHub Desktop.
Demo Sinatra App

Demo Sinatra Application for InSquared

How to use it

Install Ruby

On linux, apt-get install ruby or yum install ruby. On OS X install Hombrew then brew install ruby. On Windows use RailsInstaller.

Check out the project

git clone git://gist.github.com/2172615.git demo-sinatra-app cd demo-sinatra-app

Install Bundler

gem install bundler

Bundle the project

bundle

Run the Server

ruby app.rb

Visit the Server

http://localhost:4567

require "rubygems"
require "bundler/setup"
Bundler.require :default
enable :sessions
get "/" do
@name = session[:name]
if @name
@title = "Welcome #@name"
erb :welcome
else
@title = "Hello"
erb :index
end
end
post "/register" do
session[:name] = params[:name]
redirect "/"
end
get "/signout" do
session[:name] = nil
redirect "/"
end
source :rubygems
gem 'sinatra'
GEM
remote: http://rubygems.org/
specs:
rack (1.4.1)
rack-protection (1.2.0)
rack
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)
PLATFORMS
ruby
DEPENDENCIES
sinatra
<h1>Hello Friend, what is your name?</h1>
<form action='/register' method='post'>
<input name='name'>
</form>
<doctype html>
<html>
<head>
<title><%= @title %></title>
</head>
<body>
<%= yield %>
</body>
</html>
<h1>Welcome <%= @name %>!</h1>
<a href='/signout'>Sign out</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment