From 8e29e7639599e04bbb66f2d3395ba07fb396bbd9 Mon Sep 17 00:00:00 2001 From: lulunac27a <100660343+lulunac27a@users.noreply.github.com> Date: Mon, 26 Aug 2024 18:33:35 -0500 Subject: [PATCH] Add comments --- app.rb | 36 ++++++++++++++++++------------------ views/index.erb | 11 ++++++----- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app.rb b/app.rb index 539b6ef..1e460e5 100644 --- a/app.rb +++ b/app.rb @@ -1,30 +1,30 @@ -require 'sinatra' -require 'erb' -require 'date' +require 'sinatra' # Sinatra web server +require 'erb' # Ruby templates +require 'date' # date parser -class TaskList < Sinatra::Base - task_list = [] - id_counter = 1 +class TaskList < Sinatra::Base # task list class + task_list = [] # set initial task list to empty array + id_counter = 1 # set initial id counter to 1 - def overdue?(due_date) - Date.parse(due_date) < Date.today + def overdue?(due_date) # check if task is overdue + Date.parse(due_date) < Date.today # parse the date string end - get '/' do - @tasks = task_list - erb :index + get '/' do # get task list + @tasks = task_list # set tasks to task list array + erb :index # redirect to index page end - post '/add' do - task_list << { id: id_counter, name: params[:task], due_date: params[:due_date] } - id_counter += 1 - redirect '/' + post '/add' do # add task to task list + task_list << { id: id_counter, name: params[:task], due_date: params[:due_date] } # add task to task list + id_counter += 1 # increase id counter by 1 when task is added + redirect '/' # redirect to index page end post '/delete/:id' do - task_list.reject! { |task| task[:id] == params[:id].to_i } - redirect '/' + task_list.reject! { |task| task[:id] == params[:id].to_i } # find task to delete by task id + redirect '/' # redirect to index page end end -TaskList.run! +TaskList.run! # run the task list application diff --git a/views/index.erb b/views/index.erb index 9cb8dca..1d322ed 100644 --- a/views/index.erb +++ b/views/index.erb @@ -5,20 +5,21 @@

Task List

-
+ <%# form to add task to task list %> Name:
+ <%# all fields are required to add a task %> Due date: