ryanthtra (5) [Avatar] Offline
Should be:

res.render('users/index', {users: res.local.users, flashMessages: {success: "Loaded all users!"}});

(Replace the value of the users field with res.local.users.)
TheWexler (34) [Avatar] Offline
Thanks for the comment! In this example, we're assuming the variable 'users' is defined earlier before we return the response. Your code 'res.locals.users' assumes we already defined a local variable on the response by the name 'users' and assigned that variable to the list of users. In that case, we don't need to pass any new information from the response into the view, as it already exists in res.locals.users. In other words:

Assuming we queried the database for users and the results came back in a parameter called 'users' we can pass a local variable and assign it to the results with this code -->

res.render('users/index', {users: users, flashMessages: {success: "Loaded all users!"}});

or we can set up a local variable on the response object then render our page in a separate statement, like so -->

res.locals.users = users;
res.render('users/index', {flashMessages: {success: "Loaded all users!"}});