Update Project directory
- edit page 띄우기 완료 - edit 기능까지 구현 완료!
Showing
3 changed files
with
17 additions
and
7 deletions
... | @@ -7,8 +7,8 @@ var postSchema = mongoose.Schema({ | ... | @@ -7,8 +7,8 @@ var postSchema = mongoose.Schema({ |
7 | address:{type:String, required:[true, 'address is required!']}, | 7 | address:{type:String, required:[true, 'address is required!']}, |
8 | body:{type:String, required:[true, 'Content is required!']}, | 8 | body:{type:String, required:[true, 'Content is required!']}, |
9 | author:{type:mongoose.Schema.Types.ObjectId, ref:'user', required:true}, | 9 | author:{type:mongoose.Schema.Types.ObjectId, ref:'user', required:true}, |
10 | - createdAt:{type:Date, default:Date.now}, | 10 | + createdAt:{type:Date, default:Date.now()}, |
11 | - updatedAt:{type:Date}, | 11 | + updatedAt:{type:Date} |
12 | }); | 12 | }); |
13 | 13 | ||
14 | 14 | ... | ... |
... | @@ -4,6 +4,7 @@ var Post = require('../models/Post'); | ... | @@ -4,6 +4,7 @@ var Post = require('../models/Post'); |
4 | var util = require('../util'); | 4 | var util = require('../util'); |
5 | 5 | ||
6 | 6 | ||
7 | + | ||
7 | // Post home | 8 | // Post home |
8 | router.get('/', function(req, res){ | 9 | router.get('/', function(req, res){ |
9 | Post.find({}) | 10 | Post.find({}) |
... | @@ -55,8 +56,8 @@ router.get('/:id/edit', util.isLoggedin, checkPermission, function(req, res){ | ... | @@ -55,8 +56,8 @@ router.get('/:id/edit', util.isLoggedin, checkPermission, function(req, res){ |
55 | var errors = req.flash('errors')[0] || {}; | 56 | var errors = req.flash('errors')[0] || {}; |
56 | if(!post){ | 57 | if(!post){ |
57 | Post.findOne({_id:req.params.id}, function(err, post){ | 58 | Post.findOne({_id:req.params.id}, function(err, post){ |
58 | - if(err){return res.join(err)}; | 59 | + if(err){return res.json(err)}; |
59 | - res.render('posts/edit', {posts:post, errors:errors}); | 60 | + res.render('posts/edit', {post:post, errors:errors}); |
60 | }); | 61 | }); |
61 | } | 62 | } |
62 | else{ | 63 | else{ |
... | @@ -73,9 +74,9 @@ router.put('/:id', util.isLoggedin, checkPermission, function(req, res){ | ... | @@ -73,9 +74,9 @@ router.put('/:id', util.isLoggedin, checkPermission, function(req, res){ |
73 | if(err){ | 74 | if(err){ |
74 | req.flash('post', req.body), | 75 | req.flash('post', req.body), |
75 | req.flash('errors', util.parseError(err)); | 76 | req.flash('errors', util.parseError(err)); |
76 | - return res.redirect('/posts/'+ req.params,id + '/edit'); | 77 | + return res.redirect('/posts/'+ req.params.id + '/edit'); |
77 | }; | 78 | }; |
78 | - res.redirect('posts/' + req.params.id); | 79 | + res.redirect('/posts/' + req.params.id); |
79 | }); | 80 | }); |
80 | }); | 81 | }); |
81 | 82 | ... | ... |
... | @@ -28,13 +28,21 @@ | ... | @@ -28,13 +28,21 @@ |
28 | </div> | 28 | </div> |
29 | 29 | ||
30 | <div class="form-group"> | 30 | <div class="form-group"> |
31 | + <label for="address">address</label> | ||
32 | + <input type="text" id="address" name="address" value="<%= post.address %>" class="form-control <%= (errors.address)?'is-invalid':'' %>"> | ||
33 | + <% if(errors.address){ %> | ||
34 | + <span class="invalid-feedback"><%= errors.address.message %></span> | ||
35 | + <% } %> | ||
36 | + </div> | ||
37 | + | ||
38 | + <div class="form-group"> | ||
31 | <label for="body">Body</label> | 39 | <label for="body">Body</label> |
32 | <textarea id="body" name="body" rows="5" class="form-control <%= (errors.body)?'is-invalid':''%>"><%= post.body %></textarea> | 40 | <textarea id="body" name="body" rows="5" class="form-control <%= (errors.body)?'is-invalid':''%>"><%= post.body %></textarea> |
33 | <% if(errors.body){ %> | 41 | <% if(errors.body){ %> |
34 | <span class="invalid-feedback"><%= errors.body.message %></span> | 42 | <span class="invalid-feedback"><%= errors.body.message %></span> |
35 | <% } %> | 43 | <% } %> |
36 | </div> | 44 | </div> |
37 | - | 45 | + |
38 | <% if(errors.unhandled){ %> | 46 | <% if(errors.unhandled){ %> |
39 | <div class="invalid-feedback b-block"> | 47 | <div class="invalid-feedback b-block"> |
40 | <%= errors.unhandled %> | 48 | <%= errors.unhandled %> |
... | @@ -49,5 +57,6 @@ | ... | @@ -49,5 +57,6 @@ |
49 | </form> | 57 | </form> |
50 | 58 | ||
51 | </div> | 59 | </div> |
60 | + <%- include('../partials/gmap') %> | ||
52 | </body> | 61 | </body> |
53 | </html> | 62 | </html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment