Skip to content

Commit 6dc52fd

Browse files
committed
Ability to add new hike entry
1 parent c0b7b92 commit 6dc52fd

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

routes/hike.js

+12
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,16 @@ exports.index = function(req, res) {
1111
};
1212

1313
exports.add_hike = function(req, res){
14+
var input = req.body.hike;
15+
var hike = { HIKE_DATE: new Date(), ID: uuid.v4(), NAME: input.NAME,
16+
LOCATION: input.LOCATION, DISTANCE: input.DISTANCE, WEATHER: input.WEATHER};
17+
18+
console.log('Request to log hike:' + JSON.stringify(hike));
19+
req.app.get('connection').query('INSERT INTO HIKES set ?', hike, function(err) {
20+
if (err) {
21+
res.send(err);
22+
} else {
23+
res.redirect('/hikes');
24+
}
25+
});
1426
};

views/hike.jade

+27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ block content
44
h1= title
55
p Welcome to #{title}
66

7+
form(action="/add_hike", method="post")
8+
table(border="1")
9+
tr
10+
td Your Name
11+
td
12+
input(name="hike[NAME]", type="textbox")
13+
tr
14+
td Location
15+
td
16+
input(name="hike[LOCATION]", type="textbox")
17+
tr
18+
td Distance
19+
td
20+
input(name="hike[DISTANCE]", type="textbox")
21+
tr
22+
td Weather
23+
td
24+
input(name="hike[WEATHER]", type="radio", value="Good")
25+
| Good
26+
input(name="hike[WEATHER]", type="radio", value="Bad")
27+
| Bad
28+
input(name="hike[WEATHER]", type="radio", value="Seattle", checked)
29+
| Seattle
30+
tr
31+
td(colspan="2")
32+
input(type="submit", value="Record Hike")
33+
734
div
835
h3 Hikes
936
table(border="1")

0 commit comments

Comments
 (0)