fixed up blog example messages
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent b6bc01a · Browse files · 7 files·+33 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+33 added−15 removed
- other:+33 added−15 removed
Provenance
- Commit
d0a8305- Tree
1e1d09d- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
b6bc01a
7 files changed+33 added−15 removed
modified:examples/blog/models/post.js+3 added-3 removed
15 unmodified lines1617181920212021222324242526272839 unmodified lines15 unmodified lines fn();};
Post.prototype.validate = function(fn){ if (!this.title) return fn(new Error('_title_ required')); if (!this.body) return fn(new Error('_body_ required')); if (!this.title) return fn(new Error('title required')); if (!this.body) return fn(new Error('body required')); if (this.body.length < 10) { return fn(new Error( '_body_ should be at least **10** characters long, was only _' + this.title.length + '_')); 'body should be at least **10** characters long, was only ' + this.title.length)); } fn();};
39 unmodified linesmodified:examples/blog/public/style.css+6 added-8 removed
39 unmodified lines4041424344444546474848494950515251535455545556575639 unmodified lines}.date { font-size: 11px;}#messages ul {p.error,p.message { padding: 10px; border: 1px solid;}#messages ul li { list-style: none;p.error { background: #FDEAE7; color: #E4250C;}#messages ul.info {p.message { color: #2EBBE6; background: #F7FBFD;}#messages ul.error { color: #E4250C; background: #FDEAE7;}No newline at end of fileNo newline at end of filemodified:examples/blog/routes/post.js+5 added-4 removed
45 unmodified lines46 , post = new Post(data.title, data.body);47 48 post.validate(function(err){49 if (err) {50- req.flash('error', err.message);50+ req.session.error = err.message;51 return res.redirect('back');52 }53 54 post.save(function(err){55- req.flash('info', 'Successfully created post _%s_', post.title);55+ req.session.message = 'Successfully created the post.';56 res.redirect('/post/' + post.id);57 }); 58 });59 });21 unmodified lines81 app.put('/post/:post', function(req, res, next){82 var post = req.post;83 post.validate(function(err){84 if (err) {85- req.flash('error', err.message);85+ req.session.error = err.message;86 return res.redirect('back');87 }88+89 post.update(req.body.post, function(err){90 if (err) return next(err);90- req.flash('info', 'Successfully updated post');91+ req.session.message = 'Successfully updated post';92 res.redirect('back');93 });94 });95 });1 unmodified linemodified:examples/blog/views/post/form.jade+2 added
4 unmodified lines5 h1 Editing #{post.title}6 else7 h1 New Post8 9+ include ../messages10+11 form#post(action='/post' + (post.title ? '/' + post.id : ''), method='post')12 if post.title13 input(type='hidden', name='_method', value='put')14 p8 unmodified linesmodified:examples/blog/views/post/index.jade+2 added
5 unmodified lines6 h27 = post.title8 a.edit(href='/post/' + post.id + '/edit') Edit9 10+ include ../messages11+ 12 // dates13 p.date.created Created at #{post.createdAt}14 if post.updatedAt15 p.date.updated Updated at #{post.updatedAt}3 unmodified linesadded:examples/blog/views/messages.jade+6 added
1+2+if error3+ p.error= error4+5+if message6+ p.message= messagemodified:examples/blog/app.js+9 added
25 unmodified lines26272829303132333435363738394041425 unmodified lines25 unmodified lines app.use(express.static(__dirname + '/public')); app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));});
// Locals
app.locals.use(function(req, res){ res.locals.error = req.session.error || ''; res.locals.message = req.session.message || ''; delete req.session.error; delete req.session.message;});
// Routes
require('./routes/site')(app);require('./routes/post')(app);5 unmodified lines