-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
40 lines (33 loc) · 745 Bytes
/
app.rb
File metadata and controls
40 lines (33 loc) · 745 Bytes
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 './idea'
require 'yaml'
require 'yaml/store'
class IdeaBoxApp < Sinatra::Base
set :method_override, true
get '/' do
erb :index, locals: {ideas: Idea.all}
end
post '/' do
idea = Idea.new(params['idea_title'], params['idea_description'])
idea.save
redirect '/'
end
delete '/:index' do |index|
Idea.delete(index.to_i)
redirect '/'
end
get '/:id/edit' do |id|
idea = Idea.find(id.to_i)
erb :edit, locals: {id: id, idea: idea}
end
put '/:id' do |id|
data = {
:title => params['idea_title'],
:description => params['idea_description']
}
Idea.update(id.to_i, data)
redirect '/'
end
not_found do
erb :error
end
end