Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SailsJs res.render vs res.view

I'm trying to use SailsJs to make a simple authentication web app with PassportJs + EJS template engine.

This is my code in the AuthenController.coffee

processSignin: (req, res) ->
  passport.authenticate('local', (err, user, info) ->
    if err or not user
      return res.view('auth/signin', message:'failed')
    req.logIn user, (err) ->
      return res.view('auth/signin', message:'failed') if err
      res.redirect '/'
  ) req, res
  return

If I use: res.render('/auth/login', { message:'err' })

the browser only return HTML code of the login.ejs

If I use: res.view('/auth/login', { message:'err' }) then it return login.ejs code wrapped in the layout.ejs's <%-body%>

Any explanation for this different? Is it a new feature of Sails or built-in of Express? Where I can find documents about this?

like image 433
haotang Avatar asked Jul 09 '14 09:07

haotang


1 Answers

res.render is an expressJS method, while res.view is a SailsJs method. The latter wraps the requested view in the default layout unless a different layout is requested. So you'll have to decide whether you want just the compiled template you're requesting (res.render) or the more complete view (res.view).

like image 61
glortho Avatar answered Oct 13 '22 03:10

glortho