sails.js access controller method from controller method

iConnor picture iConnor · Dec 23, 2013 · Viewed 23.4k times · Source

How come in sails you cannot access other controller methods from within another one?

like this.

module.exports = 

   findStore: ->
       # do somthing

   index: ->
      @findStore(); # Error: undefined

Compiled

module.exports = {
  findStore: function() {},
  index: function() {
    return this.findStore(); // Error: undefined
  }
};

If you can't do this, then why not? how else should I be doing this...

Answer

nidheeshdas picture nidheeshdas · Jan 8, 2014

You can use sails.controllers.yourControllerName.findStore()

the sails global object has references to almost everything.