sails.js access model method from all controllers

61 views
Skip to first unread message

jkrab...@gmail.com

unread,
Aug 7, 2016, 2:40:37 PM8/7/16
to sails.js
I have a dynamic header menu, populated by a model method call. Instead of calling the model from every single controller, where can I put this? I tried services and I don't think models are available at that point. Policies does not seem like the best place, but if that is the only option i'll use it.
In some MVC's they have "parent" or "master" controllers that sub-controllers extend.

Also posted this to SO:
http://stackoverflow.com/questions/38807278/sails-js-access-model-method-from-all-controllers

jkrab...@gmail.com

unread,
Sep 6, 2016, 10:19:07 PM9/6/16
to sails.js
For posterity, I ended up using policies for this scenario...feels dirty.

jkrab...@gmail.com

unread,
Sep 10, 2016, 10:18:06 PM9/10/16
to sails.js
So far, the only issue I have hit with this approach is that policies are only applied to controllers, not views.
So, if you call a route that is not defined (404), the policy will not be called and an error will be called in the layout.ejs.
This produces a 404 correctly , but the page is blank, leaving visitors confused.
Even if I define a default to substitute for the value that was supposed to be set in the policy, the 404 page will still be incomplete.
Reply all
Reply to author
Forward
0 new messages