-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
40 lines (34 loc) · 759 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
require('sinatra')
require('sinatra/reloader')
also_reload('lib/**/*.rb')
require('./lib/definition')
require('./lib/word')
require('pry')
get('/') do
@words = Word.all()
erb(:word_list)
end
get('/add_word') do
erb(:add_word)
end
get('/word/:id') do
@word = Word.find(params.fetch('id').to_i())
erb(:word_info)
end
get('/word/:id/add_definition') do
@word = Word.find(params.fetch('id').to_i())
erb(:definition_form)
end
post('/word') do
@definition = Definition.new(params.fetch('definition'))
@word = Word.find(params.fetch('word_id').to_i())
@definitions = @word.define(@definition)
erb(:word_info)
end
post('/') do
word = params.fetch('word')
word = Word.new(word)
word.save()
@words = Word.all()
erb(:word_list)
end