Browse files

redirect user to post page if user is not found when creating a post

  • Loading branch information...
1 parent 7d364de commit c7d3a909eff0123758ef7da41c2506b06a4957a1 @kakchan committed Jan 24, 2012
Showing with 18 additions and 13 deletions.
  1. +18 −13 app/controllers/admin/posts_controller.js
View
31 app/controllers/admin/posts_controller.js
@@ -18,19 +18,24 @@ action('create', function() {
published: body.published === "on"
} );
User.find( req.session.user_id, function( err, user ) {
- user.posts.create(obj, function (err, post) {
- if (err) {
- flash('error', 'Post can not be created');
- render('new', {
- post: post,
- title: 'New Post'
- });
- } else {
- renameThumbnailFile( post );
- flash('info', 'Post created');
- redirect(path_to.admin_posts);
- }
- });
+ if (err) {
+ flash('error', 'Post can not be created');
+ redirect(path_to.admin_posts);
+ } else {
+ user.posts.create(obj, function (err, post) {
+ if (err) {
+ flash('error', 'Post can not be created');
+ render('new', {
+ post: post,
+ title: 'New Post'
+ });
+ } else {
+ renameThumbnailFile( post );
+ flash('info', 'Post created');
+ redirect(path_to.admin_posts);
+ }
+ });
+ }
} );
});

0 comments on commit c7d3a90

Please sign in to comment.