Created
April 6, 2012 22:39
-
-
Save rahulkmr/2323625 to your computer and use it in GitHub Desktop.
This file contains 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
require 'sinatra' | |
$fnids = {} | |
$counter = 0 | |
def store_fn(fn) | |
($fnids[$counter += 1] = fn) and $counter | |
end | |
def dispatch_fn(fnid) | |
fn = $fnids[fnid] | |
fn.nil? && 'Unknown or expired link' || fn[] | |
end | |
before do | |
halt dispatch_fn(params[:fnid].to_i) if params[:fnid] | |
end | |
get '/' do | |
<<-EOF | |
<form method="post"> | |
<input name="name" /> | |
<input type="submit" /> | |
</form> | |
EOF | |
end | |
post '/' do | |
show_name = -> { "Hello #{params[:name]}" } | |
'<a href="?fnid=%s">Click here</a>' % store_fn(show_name) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment