Fixed url redirect after submission, upvoting now works

This commit is contained in:
Nathan Leniz
2015-03-05 19:40:44 +09:00
parent 41442a540f
commit 40a42e29c2
3 changed files with 7 additions and 7 deletions

View File

@ -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()
}));
});
};

View File

@ -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;
});
};

View File

@ -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