Wednesday, 14 August 2013

Sails.js - passing data to a view

Sails.js - passing data to a view

I've recently started learning how to use Sails.js and I came across a
small issue.
I have a model called Applicant, as follows:
module.exports = {
attributes: {
name: {
type: 'STRING',
required: true
},
email: {
type: 'STRING',
required: true
}
}
};
I have built the index action to return all the instances of the Applicant
model:
module.exports = {
index: function(req, res) {
Applicant.findAll().done(function(err, applicants) {
res.view({
apps: applicants
});
});
}
};
And this is the view that I am using:
<section id="applicants">
<h1>List of applicants</h1>
<ul>
<% for (applicant in apps) { %>
<li><%= applicant.name %> <%= applicant.email %></li>
<% } %>
</ul>
</section>
Still, when I load the corresponding URL, I can't see my data displayed.
I have read the Sails.js documentation, but I can't seem to find what's
wrong with my code.
It would be great if someone could help me solve this problem.
Thank you!

No comments:

Post a Comment