JavaScript SailsJS: how to access the res.render function from anywhere

I just need to use the res.render function at some places but it is not passed to the callback I am using. Isn't there somewhere a global version of the render function or is there another way to access this?

Answer:1

In Sails v0.10.4 there is

sails.renderView(viewPath, options, callback);

Also, when rendering emails, you probably don't need to use a layout. So before calling sails.renderView, add

options.layout = false;
Answer:2

You don't need it at all places, really.

res is a response object and it makes sense only in controllers, because only controllers deal with request handling and response rendering.

Do you want to use res.render from models, services? Maybe it's because you think that all your code is always in we_have_request_and_user_is_waiting_for_response state. Well, It's not true: model methods and services can be called from sails console, or from background workers, or from code, than runs by schedule. In these cases we don't have res object at all.

Controllers are place specially designed to contain user actions responding logic. So, you should place that logic in controllers. MVC

Answer:3

How do I select DOM elements in JS? What is the equivalent for jQuery's $ selection syntax? For example I have a <div> element: <div id="idDiv">Div Element</div> Now I want to ...

How do I select DOM elements in JS? What is the equivalent for jQuery's $ selection syntax? For example I have a <div> element: <div id="idDiv">Div Element</div> Now I want to ...

I'm currently making a game, and I'm trying to change the CSS values of a whole class of objects. For a single ID, I would use, document.getElementById("idHere"), but I need something like document....

I'm currently making a game, and I'm trying to change the CSS values of a whole class of objects. For a single ID, I would use, document.getElementById("idHere"), but I need something like document....

I have the following code jQuery $(".col-md-12").hide(); $(".button-div").hide(); $(".featurette-divider").hide(); $(".footer").hide(); $(".first").fadeIn(1000); $(".second").delay(900).fadeIn(1000); ...

I have the following code jQuery $(".col-md-12").hide(); $(".button-div").hide(); $(".featurette-divider").hide(); $(".footer").hide(); $(".first").fadeIn(1000); $(".second").delay(900).fadeIn(1000); ...

I am trying to add some obstacles to the canvas game that I've got but something seems to be wrong and I can't seem to put my finger on it. I just want some simple walls here and there to make the ...

I am trying to add some obstacles to the canvas game that I've got but something seems to be wrong and I can't seem to put my finger on it. I just want some simple walls here and there to make the ...