forked from TreeHacks/hackpack-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
79 lines (51 loc) · 1.87 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'rubygems'
require 'active_record'
require 'sinatra'
require 'sinatra/activerecord'
set :database, { adapter: 'sqlite3', database: 'treeyak.sqlite3' }
class Yak < ActiveRecord::Base
end
get '/' do
# BEGIN YOUR CODE HERE
# Here, you should store all the Yak's in the database in a variable called yaks.
# END YOUR CODE HERE
erb :index, locals: { yaks: yaks }
end
get '/new_yak' do
erb :new_yak
end
post '/new_yak' do
contents = params['contents']
# BEGIN YOUR CODE HERE
# In this section, you should create a new yak, initialize it with the data from the form, and then save it to the database.
# END YOUR CODE HERE
redirect to('/')
end
post '/upvote' do
yak_id = params['yak_id']
# BEGIN YOUR CODE HERE
# In this section, you should increment the yak's upvotes by 1 and return the new number of upvotes in json.
# (Note: This will be called via AJAX, so you don't need to render any html or redirect to any other page.)
# END YOUR CODE HERE
end
post '/downvote' do
yak_id = params['yak_id']
# BEGIN YOUR CODE HERE
# In this section, you should decrement the yak's upvotes by 1 and return the new number of upvotes in json.
# (Note: This will be called via AJAX, so you don't need to render any html or redirect to any other page.)
# END YOUR CODE HERE
end
get '/hot' do
# BEGIN YOUR CODE HERE
# Here, you should use the order method on the Yak class to get all the Yaks ordered by upvotes.
# The order method takes one parameter, which is the field you want to order by.
# END YOUR CODE HERE
erb :index, locals: { yaks: yaks }
end
get '/new' do
# BEGIN YOUR CODE HERE
# Here, you should use the order method on the Yak class to get all the Yaks ordered by it's created_at field.
# The order method takes one parameter, which is the field you want to order by.
# END YOUR CODE HERE
erb :index, locals: { yaks: yaks }
end