mirror of
				https://github.com/sinatra/sinatra
				synced 2023-03-27 23:18:01 -04:00 
			
		
		
		
	todo started
This commit is contained in:
		
							parent
							
								
									22945ab100
								
							
						
					
					
						commit
						e2fd51dc25
					
				
					 2 changed files with 50 additions and 0 deletions
				
			
		
							
								
								
									
										13
									
								
								examples/todo/development.log
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								examples/todo/development.log
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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"}
 | 
			
		||||
							
								
								
									
										37
									
								
								examples/todo/todo.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								examples/todo/todo.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue