Skip to content

Commit 123c3e7

Browse files
committed
Implement the fourth assignment in ruby
[refs #b7400db79a80]
1 parent 6119d58 commit 123c3e7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

developing/examples/webapp/ruby/app.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,33 @@
99
ENV['POSTGRES_USER'], ENV['POSTGRES_PASSWORD'])
1010
sql = "INSERT INTO requests (ip, path, host, requested_at) VALUES ($1, $2, $3, $4)"
1111
res = conn.exec(sql, [request.ip, '/', Socket.gethostname, Time.now])
12+
13+
sql = "SELECT ip, path, host, requested_at FROM requests ORDER BY id DESC LIMIT 25;"
14+
res = conn.exec(sql)
15+
1216
conn.finish
13-
'Hello, World!'
17+
18+
requests_table = res.map do |row|
19+
values = row.map do |column|
20+
"<td>#{column[1]}</td>"
21+
end.join('')
22+
"<tr>#{values}</tr>"
23+
end.join('')
24+
25+
<<-BODY
26+
<html>
27+
<body>
28+
<h1>The requests</h1>
29+
<table style="width: 100%;" border="1">
30+
<tr>
31+
<th>IP</th>
32+
<th>Path</th>
33+
<th>Container</th>
34+
<th>Timestamp</th>
35+
</tr>
36+
#{requests_table}
37+
</table>
38+
</body>
39+
</html>
40+
BODY
1441
end

developing/examples/webapp/ruby/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.3'
22

33
services:
44
app:
5-
image: jfahrer/webapp-ruby:v3
5+
image: jfahrer/webapp-ruby:v4
66
build:
77
context: .
88
environment:

0 commit comments

Comments
 (0)