Skip to content

Instantly share code, notes, and snippets.

@oogali
Created February 22, 2012 23:51
Show Gist options
  • Save oogali/1888474 to your computer and use it in GitHub Desktop.
Save oogali/1888474 to your computer and use it in GitHub Desktop.
Short intro to Sinatra
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'haml'
get '/' do
haml :ask
end
post '/' do
if params['name']
@name = params['name']
haml :answer
else
redirect '/'
end
end
__END__
@@ layout
!!!
%html
%head
%title= 'lol'
%body
%h1= 'oh snap, templates!'
=yield
@@ ask
%form{ :method => 'POST', :action => '/' }
What is your name?
%br
%input{ :name => 'name', :type => 'text', :size => 30, :placeholder => 'Frodo, Waldo, James, etc.' }
%input{ :type => 'submit', :value => 'go!' }
@@ answer
%strong
Hi #{@name}!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment