Created
February 22, 2012 23:51
-
-
Save oogali/1888474 to your computer and use it in GitHub Desktop.
Short intro to Sinatra
This file contains hidden or 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
#!/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