Code Monkey home page Code Monkey logo

sails-hook-flash's Introduction

sails-hook-flash

NPM Version NPM Download Travis CI Coverage Status

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 message
  • request.getFlash(type) - Returns all messages from a type
  • request.hasFlash(type) - Checks if a message type was stored

View layer

  • flash.all() - Returns all messages
  • flash.get(type) - Returns all messages from a type
  • flash.has(type) - Checks if a message type was stored

sails-hook-flash's People

Contributors

dudemelo avatar followtheart avatar robjr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sails-hook-flash's Issues

Error when utilizing Sails session config: routesDisabled

Got the error below when hitting a route configured with routesDisabled

Sails Version: 0.12.0

TypeError: Cannot read property 'flash' of undefined
at module.exports (/path/to/project/node_modules/sails-hook-flash/lib/flash.js:24:25)

Applied a dirty _.get() implementation on line 24 just to proceed.

if (typeof _.get(req,"session[_session_key]", "") === 'undefined') {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.