javascriptnode.jssails.jscontrollers

sails.js access controller method from controller method


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...


Solution

  • Having the same problem for last few hours. I used the api/services folder. It may not be exactly what you need but it is an option. A good explanation is here. What services would one add to the api/services folder in sails.js