Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

todo started

  • Loading branch information...
commit e2fd51dc2586b1351f714a68258d3211b785038d 1 parent 22945ab
blake.mizerany@gmail.com authored
Showing with 50 additions and 0 deletions.
  1. +13 −0 examples/todo/development.log
  2. +37 −0 examples/todo/todo.rb
View
13 examples/todo/development.log
@@ -0,0 +1,13 @@
+GET / | Status: 200 | Params: {:format=>"html"}
+Redirecting to: /
+POST / | Status: 302 | Params: {:format=>"html", :_method=>"index"}
+GET / | Status: 200 | Params: {:format=>"html"}
+Redirecting to: /
+POST / | Status: 302 | Params: {:format=>"html", :_method=>"index"}
+GET / | Status: 200 | Params: {:format=>"html"}
+Redirecting to: /
+POST / | Status: 302 | Params: {:format=>"html", :_method=>"index"}
+GET / | Status: 200 | Params: {:format=>"html"}
+Redirecting to: /
+POST / | Status: 302 | Params: {:format=>"html", :_method=>"index"}
+GET / | Status: 200 | Params: {:format=>"html"}
View
37 examples/todo/todo.rb
@@ -0,0 +1,37 @@
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
+require 'sinatra'
+
+get '/' do
+ @items = session[:items] || []
+ haml <<-haml
+%script window.document.getElementById('new_item').focus();
+%h1 Sinatra's todo list
+%ul
+ - @items.each_with_index do |item, index|
+ %li.item
+ %div
+ = item
+ %form{:action => "/", :method => 'POST'}
+ %input{:type => 'hidden', :name => '_method', :value => 'index'}
+ %input{:type => 'submit', :value => 'delete'}
+%form{:action => '/clear', :method => 'POST'}
+ %input{:value => 'clear', :type => :submit}
+%form{:action => '/', :method => 'POST'}
+ %input{:type => 'textbox', :name => :new_item, :id => 'new_item'}
+ %input{:type => 'submit'}
+ haml
+end
+
+post '/' do
+ (session[:items] ||= []) << params[:new_item] unless params[:new_item].to_s.strip.empty?
+ redirect '/'
+end
+
+post '/clear' do
+ session[:items].clear
+ redirect '/'
+end
+
+delete '/:id' do
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.