vendredi 3 avril 2015

Can partials access locals in sails? why not?

I have an index.ejs for my homepage that renders <%- partial ('../user/new.ejs') %> for my signup page. In the process of adding flash error messages I noticed that the partial does not have access to locals [flash undefined error]. Meanwhile if I load the partial as a view (by accessing root/user/new directly then the flash messages are executed properly.


Could someone explain why this is, and is there any work around?


Controller:



create: function (req, res, next) {

User.create({
email: req.param('email'),
encryptedPassword: req.param('password')
}, function userCreated(err, user) {
if (err) {
console.log(err);

req.session.flash = {
err: err.ValidationError
}

return res.redirect('/');
}
res.redirect('/user/show/'+ user.id);
//res.json(user);
});
},


index.ejs is just <%- partial ('../user/_signup.ejs') %> for now


_signup.ejs



<div class="col-sm-12 col-md-12 col-lg-12" style="max-width:400px;">
<h1>Sign up</h1>
<form action="/user/create" method="post" role="form" class="form-signin">


<% if(flash && flash.err) { %>
<ul class="alert alert-success">
<% Object.keys(flash.err).forEach(function(err) { %>
<li> <%- JSON.stringify(flash.err[err]) %></li>
<% }) %>
</ul>
<% } %>

<div class="form-group control-group">
<label for="email"></label>
<input name="email" class="form-control" placeholder="Email" type="text"/>
</div>

<div class="form-group control-group">
<label for="password"></label>
<input name="password" class="form-control" placeholder="Password" id="password" type="password" title="Password"/>
</div>

<div class="form-group control-group">
<label for="passwordConfirmation"></label>
<input name="passwordConfirmation" class="form-control" placeholder="Confirm Password" type="password" title="Password"/>
</div>

<input type="submit" value="Signup" class="btn btn-success"/>
<input type="hidden" name="_csrf" value="<%= _csrf %>"/>
</form>

Aucun commentaire:

Enregistrer un commentaire