I've been trying to establish a connection for hours but haven't had any luck.
All I want to do is transfer some data from a controller to a view template. When I navigate the route without specifying a view template, the browser displays the data in JSON format (confirming that the MYSQL connection is functioning).
However, every time I attempt to link to MYSLQ data (or any data from the controller to the view) to pass it to the template, Sails throws an error stating that the data cannot be found (even though it's visible when returning the JSON data). I suspect this issue may be related to how SailsJS attempts to connect with the EJS template engine or if there's a breakdown between the Model, Controller, and View on the backend?
Below is a simple example that isn't working, yet my ultimate goal is to connect to a MYSQL list of data:
Declaration in Routes.js:
'GET /schools': { view: 'schools/index', controller: "SchoolsController", action:"index"},
SchoolsController.js:
module.exports = {
index: function(req, res){
// Just sending this to the view
res.view({
"name": "Iparra"
})
}
};
index.ejs template:
<div id="theschools">
<h1>List of Schools</h1>
<%= name %>
</div>
Error received from Sails.js:
{
"stack": "ReferenceError: /Users/mnelson/Documents/Mike Files 2/Personal/MyDesign Musings/sails/test-project/views/schools/index.ejs:7\n 5| <h1>List of Schools</h1>\n 6| \n >> 7| <%= name %>\n 8| \n 9| </div>\n 10| \n\nname is not defined\n at eval (eval at <anonymous> (/usr/local/lib/node_modules/sails/node_modules/ejs-locals/node_modules/ejs/lib/ejs.js:237:14), <anonymous>:30:109)\n [truncated]",
"message": " /Users/mnelson/Documents/Mike Files 2/Personal/My Design Musings/sails/test-project/views/schools/index.ejs:7\n 5| <h1>List of Schools</h1>\n 6| \n >> 7| <%= name %>\n 8| \n 9| </div>\n 10| \n\nname is not defined",
"path": "/Users/mnelson/Documents/Mike Files 2/Personal/My Design Musings/sails/test-project/views/schools/index.ejs"
}