2

I'm trying to render "result" in my "home-page" view using this function in my controller, which is calling my model to make the query.

exports.searchNoms = (req, res) => {
    getDatabaseModel.searchNoms(req).then(function(result) {
        console.log(result);
        res.render('Home/home-page', {
            nomenclature: result
        });
    }).catch((err) => setImmediate(() => {
        throw err;
    }))
};

I'm getting my result which displays a string as I wanted.

But then I'm getting the following error : TypeError: Cannot read property 'render' of undefined at C:\somepath\controllers\nomenclature.controller.js:36:14

I've tried a few things and if I change my route calling this function in my controller from :

`router.post('/search-noms', function (req, res) {nomenclatureController.searchNoms(req.body.idNoms)})`

To :

`router.post('/search-noms', nomenclatureController.searchNoms)`

It works. But I need that body parameter in order to achieve what I want to do.

Am I missing something here ?

0

1 Answer 1

1

mark1: Just get idNoms from your req.body, and put it into getDatabaseModel.searchNoms(idNoms), that's all.

exports.searchNoms = (req, res) => {
    // mark1
    const idNoms = req.body.idNoms

    getDatabaseModel.searchNoms(idNoms).then(function(result) {
        console.log(result);
        res.render('Home/home-page', {
            nomenclature: result
        });
    }).catch((err) => setImmediate(() => {
        throw err;
    }))
};

Then in your router

router.post('/search-noms', nomenclatureController.searchNoms)
Sign up to request clarification or add additional context in comments.

1 Comment

Can't believe I got stuck on that ;_; Thank you very much !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.