sails-hook-flash
v0.2.2
Published
The simplest way to use flash message in your Sails application
Downloads
273
Maintainers
Readme
sails-hook-flash
The simplest way to use flash messages in your Sails application. This is useful when you want to redirect and have a special message shown on the next page.
Installation
npm install sails-hook-flash
Use --save
to add in your package.json.
Example
Adding a new flash message:
// api/controllers/SampleController.js
login: function (request, response) {
request.addFlash('success', 'A success message.');
return response.redirect('/sample/success');
}
Rendering your flash message:
// views/sample/success.ejs
<% flash.get('success').forEach(function (message) { %>
<div style="color:green;">
<%= message %>
</div>
<% }) %>
NOTE: The EJS view engine is used in this sample, but you're not limited to it.
Usage
Controller layer
request.addFlash(type, message)
- Stores a new messagerequest.getFlash(type)
- Returns all messages from a typerequest.hasFlash(type)
- Checks if a message type was stored
View layer
flash.all()
- Returns all messagesflash.get(type)
- Returns all messages from a typeflash.has(type)
- Checks if a message type was stored