Sails.js flash message for user registration

后端 未结 3 997
不思量自难忘°
不思量自难忘° 2020-12-30 15:12

I am following Sail.js tutorial from http://irlnathan.github.io/sailscasts/blog/2013/08/27/building-a-sails-application-ep4-handling-validation-errors-with-a-flash-message/<

3条回答
  •  梦谈多话
    2020-12-30 15:27

    In a normal mvc like rails or cakephp handling flash is something like this: $this->Flash->error('An Error Occurred Message'); then displayed it in an element.

    In sails it should be simple as that.

    In Controller: req.flash('error', 'An Error Occurred Message');

    In View Partial: flash.ejs

    <% if (req.session.flash) { %>
    
        <% if (req.session.flash.success) { %>
        
    <%= req.flash('success') %> ×
    <% } %> <% if (req.session.flash.warning) { %>
    <%= req.flash('warning') %> ×
    <% } %> <% if (req.session.flash.error) { %>
    <%= req.flash('error') %> ×
    <% } %> <% } %>

    On Layout:

    <%- partial('partials/flash') %>
    

    Handling Error Message per field should be part in a Validation and Html Helper. (Like for example: https://gist.github.com/mikermcneil/8366092)

提交回复
热议问题