forked from makersacademy/chitter-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
40 lines (34 loc) · 879 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
require 'sinatra/base'
require 'sinatra/reloader'
require_relative 'lib/peep_repository'
require_relative 'lib/user_repository'
require_relative 'lib/database_connection'
DatabaseConnection.connect
class Application < Sinatra::Base
# This allows the app code to refresh
# without having to restart the server.
configure :development do
register Sinatra::Reloader
end
get '/' do
peep_repo = PeepRepository.new
@user_repo = UserRepository.new
@peep_list = peep_repo.all
return erb(:index)
end
post '/' do
repo = PeepRepository.new
@user_repo = UserRepository.new
peep = Peep.new
peep.title = params[:title]
peep.content = params[:content]
peep.time_stamp = Time.new
peep.user_id = 1
repo.create(peep)
@peep_list = repo.all
return erb(:index)
end
get "/signup" do
return erb(:signup)
end
end