Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 777
iConnor Avatar asked Dec 22 '13 23:12

iConnor


1 Answers

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

the sails global object has references to almost everything.

like image 78
nidheeshdas Avatar answered Oct 04 '22 17:10

nidheeshdas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!