From 40a42e29c2322510545cfb74f7408c3f8ea0b37e Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Thu, 5 Mar 2015 19:40:44 +0900 Subject: [PATCH] Fixed url redirect after submission, upvoting now works --- controllers/story.js | 9 +++++---- public/js/main.js | 4 +--- views/stories/show.jade | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/story.js b/controllers/story.js index 581bb5e50b..0e7744071a 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -29,9 +29,11 @@ exports.index = function(req, res, next) { exports.returnIndividualStory = function(req, res, next) { var dashedName = req.params.storyName; - storyName = dashedName.replace(/\-/g, ' '); + var storyName = dashedName.replace(/\-/g, ' '); - Story.find({'headline' : new RegExp(storyName, 'i')}, function(err, story) { + debug('looking for %s', storyName); + + Story.find({'storyLink' : new RegExp(storyName, 'i')}, function(err, story) { if (err) { next(err); } @@ -134,11 +136,10 @@ exports.storySubmission = function(req, res, next) { story.save(function(err, data) { if (err) { - throw err; + return res.status(500); } res.send(JSON.stringify({ storyLink: story.storyLink.replace(/\s/g, '-').toLowerCase() })); }); - }; diff --git a/public/js/main.js b/public/js/main.js index 0b3dee6fb0..8a5f8216c3 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -177,9 +177,7 @@ $(document).ready(function() { $('#story-submit').bind('click', storySubmitButtonHandler); }) .done(function (data, textStatus, xhr) { - window.dataReturn = data; - console.log(data); - window.location = '/stories/' + data.storyLink; + window.location = '/stories/' + JSON.parse(data).storyLink; }); }; diff --git a/views/stories/show.jade b/views/stories/show.jade index 9024bf9711..c02ee316d5 100644 --- a/views/stories/show.jade +++ b/views/stories/show.jade @@ -5,6 +5,7 @@ block content var storyId = !{JSON.stringify(id)}; var comments = !{JSON.stringify(comments)}; var upVotes = !{JSON.stringify(upVotes)}; + var user = !{JSON.stringify(user)}; .panel.panel-info .panel-heading.text-center Camper News