質問編集履歴
1
自分用に修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
localhost:3000/
|
5
|
+
localhost:3000/ringos/new からクエリ登録しようとすると、
|
6
6
|
|
7
7
|
登録もされず、
|
8
8
|
|
9
|
-
Cannot POST /
|
9
|
+
Cannot POST /ringos/ringos
|
10
10
|
|
11
11
|
と表示されます。
|
12
12
|
|
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
const PORT = process.env.PORT || 3000;
|
34
34
|
|
35
|
-
const
|
35
|
+
const Ringo = require('./models/ringos')
|
36
36
|
|
37
37
|
/*******
|
38
38
|
|
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
useNewUrlParser: true,
|
48
48
|
|
49
|
-
useUnifiedTopo
|
49
|
+
useUnifiedToporingoy: true,
|
50
50
|
|
51
51
|
useCreateIndex: true,
|
52
52
|
|
@@ -56,7 +56,7 @@
|
|
56
56
|
|
57
57
|
mongoose.connection.once('open', () => {
|
58
58
|
|
59
|
-
console.
|
59
|
+
console.ringo('connected to mongo')
|
60
60
|
|
61
61
|
})
|
62
62
|
|
@@ -68,13 +68,13 @@
|
|
68
68
|
|
69
69
|
app.use((req, res, next) => {
|
70
70
|
|
71
|
-
console.
|
71
|
+
console.ringo('**********************')
|
72
|
-
|
72
|
+
|
73
|
-
console.
|
73
|
+
console.ringo('***********Middleware checking in***********')
|
74
|
-
|
74
|
+
|
75
|
-
console.
|
75
|
+
console.ringo('I run before all routes')
|
76
|
-
|
76
|
+
|
77
|
-
console.
|
77
|
+
console.ringo('**********************')
|
78
78
|
|
79
79
|
next()
|
80
80
|
|
@@ -90,9 +90,9 @@
|
|
90
90
|
|
91
91
|
*/
|
92
92
|
|
93
|
-
app.get('/
|
93
|
+
app.get('/ringos/', (req, res) => {
|
94
|
-
|
94
|
+
|
95
|
-
|
95
|
+
Ringo.find({}, (err, foundRingos)=>{
|
96
96
|
|
97
97
|
if(err){
|
98
98
|
|
@@ -106,7 +106,7 @@
|
|
106
106
|
|
107
107
|
res.render('Index', {
|
108
108
|
|
109
|
-
|
109
|
+
ringos: foundRingos
|
110
110
|
|
111
111
|
})
|
112
112
|
|
@@ -126,7 +126,7 @@
|
|
126
126
|
|
127
127
|
*/
|
128
128
|
|
129
|
-
app.get('/
|
129
|
+
app.get('/ringos/new', (req, res) => {
|
130
130
|
|
131
131
|
res.render('New')
|
132
132
|
|
@@ -140,21 +140,21 @@
|
|
140
140
|
|
141
141
|
*/
|
142
142
|
|
143
|
-
app.delete('/
|
143
|
+
app.delete('/ ringos/:id', (req, res) => {
|
144
|
-
|
144
|
+
|
145
|
-
|
145
|
+
Ringo.findByIdAndDelete(req.params.id, (err, foundRingo)=>{
|
146
|
-
|
146
|
+
|
147
|
-
if(err){
|
147
|
+
if(err){
|
148
|
-
|
148
|
+
|
149
|
-
res.status(404).send({
|
149
|
+
res.status(404).send({
|
150
|
-
|
150
|
+
|
151
|
-
msg: err.message
|
151
|
+
msg: err.message
|
152
|
-
|
152
|
+
|
153
|
-
})
|
153
|
+
})
|
154
|
-
|
154
|
+
|
155
|
-
} else {
|
155
|
+
} else {
|
156
|
-
|
156
|
+
|
157
|
-
res.redirect('/
|
157
|
+
res.redirect('/ringos')
|
158
158
|
|
159
159
|
}
|
160
160
|
|
@@ -172,9 +172,9 @@
|
|
172
172
|
|
173
173
|
*/
|
174
174
|
|
175
|
-
app.post('/
|
175
|
+
app.post('/ringos', (req, res) =>{
|
176
|
-
|
176
|
+
|
177
|
-
|
177
|
+
Ringo.create(req.body, (err, createdRingo ) => {
|
178
178
|
|
179
179
|
if(err){
|
180
180
|
|
@@ -186,9 +186,9 @@
|
|
186
186
|
|
187
187
|
} else {
|
188
188
|
|
189
|
-
console.
|
189
|
+
console.ringo(createdRingo);
|
190
|
-
|
190
|
+
|
191
|
-
res.redirect('/
|
191
|
+
res.redirect('/ringos')
|
192
192
|
|
193
193
|
}
|
194
194
|
|
@@ -206,9 +206,9 @@
|
|
206
206
|
|
207
207
|
|
208
208
|
|
209
|
-
app.get('/
|
209
|
+
app.get('/ringos/:id/edit', (req, res) => {
|
210
|
-
|
210
|
+
|
211
|
-
|
211
|
+
Ringo.findById(req.params.id, (err, foundRingo)=>{
|
212
212
|
|
213
213
|
if(err){
|
214
214
|
|
@@ -222,7 +222,7 @@
|
|
222
222
|
|
223
223
|
res.render('Edit', {
|
224
224
|
|
225
|
-
|
225
|
+
ringo: foundRingo
|
226
226
|
|
227
227
|
})
|
228
228
|
|
@@ -240,9 +240,9 @@
|
|
240
240
|
|
241
241
|
*/
|
242
242
|
|
243
|
-
app.get('/
|
243
|
+
app.get('/ringos/:id', (req, res) => {
|
244
|
-
|
244
|
+
|
245
|
-
|
245
|
+
Ringo.findById(req.params.id, (err, foundRingo)=>{
|
246
246
|
|
247
247
|
if(err){
|
248
248
|
|
@@ -256,7 +256,7 @@
|
|
256
256
|
|
257
257
|
res.render('Show', {
|
258
258
|
|
259
|
-
|
259
|
+
ringo: foundRingo
|
260
260
|
|
261
261
|
})
|
262
262
|
|
@@ -274,9 +274,9 @@
|
|
274
274
|
|
275
275
|
*/
|
276
276
|
|
277
|
-
app.get('/
|
277
|
+
app.get('/ringos/:id', (req, res) => {
|
278
|
-
|
278
|
+
|
279
|
-
|
279
|
+
Ringo.findById(req.params.id, (err, foundRingo)=>{
|
280
280
|
|
281
281
|
if(err){
|
282
282
|
|
@@ -290,7 +290,7 @@
|
|
290
290
|
|
291
291
|
res.redirect('Index', {
|
292
292
|
|
293
|
-
|
293
|
+
ringo: foundRingo
|
294
294
|
|
295
295
|
})
|
296
296
|
|
@@ -304,7 +304,7 @@
|
|
304
304
|
|
305
305
|
app.listen(PORT, () => {
|
306
306
|
|
307
|
-
console.
|
307
|
+
console.ringo('We in the building', PORT)
|
308
308
|
|
309
309
|
})
|
310
310
|
|
@@ -328,9 +328,9 @@
|
|
328
328
|
|
329
329
|
<div>
|
330
330
|
|
331
|
-
<h1>New
|
331
|
+
<h1>New Ringo</h1>
|
332
|
-
|
332
|
+
|
333
|
-
<form action="
|
333
|
+
<form action="ringos" method="POST">
|
334
334
|
|
335
335
|
title: <input type="text" name="name" /><br />
|
336
336
|
|
@@ -338,7 +338,7 @@
|
|
338
338
|
|
339
339
|
shipIsBroken: <input type="checkbox" name="shipIsBroken" /><br />
|
340
340
|
|
341
|
-
<input type="submit" name="" value="New
|
341
|
+
<input type="submit" name="" value="New Ringo" />
|
342
342
|
|
343
343
|
</form>
|
344
344
|
|
@@ -358,13 +358,13 @@
|
|
358
358
|
|
359
359
|
```
|
360
360
|
|
361
|
-
|
361
|
+
ringos.jsファイル
|
362
362
|
|
363
363
|
```JavaScript
|
364
364
|
|
365
365
|
const { Schema, model } = require('mongoose');
|
366
366
|
|
367
|
-
const
|
367
|
+
const ringoSchema = new Schema({
|
368
368
|
|
369
369
|
title: { type: String, required: true, unique: true },
|
370
370
|
|
@@ -378,9 +378,9 @@
|
|
378
378
|
|
379
379
|
|
380
380
|
|
381
|
-
const
|
381
|
+
const Ringo = model('Ringo', ringoSchema);
|
382
|
-
|
382
|
+
|
383
|
-
module.exports =
|
383
|
+
module.exports = Ringo;
|
384
384
|
|
385
385
|
|
386
386
|
|