Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
niczak committed Apr 14, 2012
0 parents commit 409be03
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
A sample application built with Sinatra featuring multiple GET/POST routes and examples on how to work with POST data.

Assuming you have Ruby installed:
- 'gem install sinatra'
- 'gem install shotgun'

Clone the repo and run:
- 'shotgun frank.rb'
49 changes: 49 additions & 0 deletions frank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'rubygems'
require 'sinatra'

# Define not_found route if we want to avoid display the default
# not_found do
# halt 404, 'page not found!'
# end

# Begin GET routes
get '/' do
erb :home
end

get '/about' do
"Frank is the man, what more do you need to know?"
end

get '/decrypt/:secret' do
params[:secret].reverse
end

get '/form' do
#load embedded ruby file from /views
erb :form
end

get '/hello/:name/:city' do
"Hello there, #{params[:name].capitalize} from #{params[:city]}."
end

get '/more/*' do
#display all params passed to route
params[:splat]
end

get '/reverse' do
erb :reverse
end
#End GET routes

#Begin POST routes
post '/form' do
"You said '#{params[:message]}'"
end

post '/reverse' do
params[:secret].reverse
end
#End POST routes
5 changes: 5 additions & 0 deletions views/form.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h3>Display POST</h3>
<form action="/form" method="post">
<input type="text" name="message">
<input type="submit">
</form>
11 changes: 11 additions & 0 deletions views/home.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h3>Sinatra Example</h3>
<p>
Available Routes:
<ul>
<li><a href="/about">About [Text]</a></li>
<li><a href="/form">Form [POST Example]</a></li>
<li><a href="/hello/niczak/Minneapolis">Hello [2 Params]</a></li>
<li><a href="/more/foo/bar">More [Splat Example]</a></li>
<li><a href="/reverse">Reverse [String Reversal]</a></li>
</ul>
</p>
5 changes: 5 additions & 0 deletions views/reverse.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h3>String Reversal</h3>
<form action="/reverse" method="post">
<input type="text" name="secret">
<input type="submit">
</form>

0 comments on commit 409be03

Please sign in to comment.