forked from makersacademy/todo-list-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
43 lines (36 loc) · 860 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'sinatra/base'
require_relative 'lib/todolist'
class ToDoListApp < Sinatra::Base
#this creates an instance of the todolist
$todolist = ToDoList.new
get '/' do
erb :index
end
# GET REQUEST FROM CONTROLLER
get '/todolist' do
#ASK MODEL FOR TODO ITEMS
@items = $todolist.items
# ASK VIEW FOR HTML INCLUDING TODO ITEMS
response = erb :todos
#SEND RESPONSE TO SERVER
response
end
get '/add-item' do
response = erb :add_item
response
end
post '/add-item' do
name = params[:name]
category = params[:category]
$todolist.add_item(name,category)
response = redirect('/todolist')
response
end
get '/bycategory' do
category = params[:category]
@items = $todolist.by_category(category)
response = erb :items_by_category
response
end
run! if app_file == $0
end