I'm still new to sails.js and currently trying to get returned object from different action.
What currently I know is if I use 'getUserTransaction' action inside 'UserController', then I can only return it to 'getUserTransaction.ejs' view using locals (_.each). (CMIIW) example:
//UserController
getUserTransaction: function (req, res, next){
UserTransaction.find({user:req.param('userid')}).exec(function foundTransactions(err, transactions){
if(err) return next(err);
if(!transactions) return next();
res.view({
transactions: transactions
});
});
}
//getUserTransaction.ejs
...
<% _.each(transactions, function(transaction){ %>
<tr>
<td><%= transaction.data %></td>
<td><a href="<%= transaction.path %>">Link</a></td>
</tr>
<% }); %>
...
But, what if I want to return object from 'getUserHobby' action indside 'UserController' to 'getUserTransaction.ejs' view?. this is my code and I can't get it right
//UserController
getUserHobby: function (req, res, next){
UserHobby.find({user:req.param('userid')}).exec(function foundHobbies(err, hobbies){
if(err) return next(err);
if(!hobbies) return next();
res.view('user/getUserTransaction', {
hobbies: hobbies
});
});
}
//getUserTransaction.ejs
...
<% _.each(hobbies, function(hobby){ %>
<tr>
<td><%= hobby.type %></td>
<td><%= hobby.name %></td>
</tr>
<% }); %>
...
And I've tried to do it and returned 'hobbies undefined'. So how I should get it right.
Regards