I am new to express node and I am responsible for the front end of a web app. I need to be able to have the user press a link and for that link to when press pass variable to index.js this link lets the user choose what category of question that they want to be tested on. I do not think that having a different route for each category is the best option. but because I am new I am not sure what to do.
Here is the code for my link in jade (I want to add something here to do what I want) there is a link to a screenshot of the page at the bottom of this post.
li.active
a(href='freeplay')
i.fa.fa-edit
span.nav-label Freeplay
span.fa.arrow
ul.nav.nav-second-level
li
a(href='freeplay/category') Category1
li
a(href='freeplay/category') Category2
li
a(href='freeplay/category') Category3
li
a(href='freeplay/category') Category4
li
a(href='freeplay/category') Category5
and Here is my index.js that handles it. temp is the variable that I want to hold the string of the category.
//Handle the free play request
router.get('/freeplay' , isAuthenticated, freeplay.startFreePlay);
//Handle the free play request with category
router.get('/freeplay/category' , isAuthenticated, freeplay.startCategoryPlay);
and finally the node.js that I want to be able to read a variable in to temp is the variable I want to assign the user chosen category to.
exports.startFreePlay = function(req, res) {
//grab a question that the user has not gotten right
//Get the users logged in id
userId = req.session.passport.user;
freePlayLogic.getQuestion(userId, function(question){
res.render("FreePlayQuestion", { question: question , questionID : question._id.toString()});
})
//Pass the question to render
};
exports.startCategoryPlay = function(req, res){
//grab a question that the user has not gotten right
//Get the users logged in id
userId = req.session.passport.user;
/**
* get a question from category "temp"
*/
freePlayLogic.getQuestionFromCategory(userId, "temp", function(question){
res.render("FreePlayQuestion", { question: question , questionID : question._id.toString()});
})
}
Thanks in advance for help!
here is a screenshot of the web app with the category choices