javascript - Sails JS - Display flash message doesn't work on Heroku(production) but works fine in development -
the flash message works on local machine during development...it doesn't work when deployed app on heroku. i've been trying find answer couldn't find solves problem.
api/policies/flash.js
module.exports = function(req, res, next) {     res.locals.flash = {};     if(!req.session.flash) return next();     res.locals.flash = _.clone(req.session.flash);      // clear flash     req.session.flash = {};      next(); };   api/controller/usercontroller.js (within create action) - when form submitted successfully, redirect homepage , display thank message.
res.redirect("/"); req.flash('signup-message', '<div class="thankyou-message-wrapper bg-success"><span class="glyphicon glyphicon-remove pull-right" aria-hidden="true"></span><span class="thankyou-message">thank submitting form!<br> our administer review submission , publish soon.</span></div>');   view/main/index.ejs - how render message usercontroller.js
<%- req.flash('signup-message') %>   does have insight why flash message not showing when deployed on heroku?
you need add policy routes.js file enable policy homepage. example:
 '/': {       view: 'homepage', policy: 'flash'  }   then in usercontroller, add message session.flash:
 req.session.flash = {       message : '<div class="thankyou-message-wrapper bg-success"><span class="glyphicon glyphicon-remove pull-right" aria-hidden="true"></span><span class="thankyou-message">thank submitting form!<br> our administer review submission , publish soon.</span></div>'  }   finally, display message in homepage, first check if message exists , display:
 <% if(flash && flash.message) { %>       <%- flash.message %>  <% } %>      
Comments
Post a Comment