1

I am trying to add a method available for all controllers in sailsjs, much like the blueprint methods are. The method should also be exposed to a REST route (like /modelName/myBlueprintMethod).

How can I go about and do this?

I have seen lots of Qs for how to override the blueprint methods but what i need is extend the blueprint.

A little context.
What I want to achieve is to expose the schema of the model related to the controller to automate some front-end CMS.

Thanks

Juan Solano
  • 1,188
  • 1
  • 17
  • 32

2 Answers2

0

I also wanted a similar solution, although it would be a subset of your question: Asked a question here.

One way to go about this (and there could be others) is:

Make a service, send it the parameters and use it in all controllers. Hope this helps.

Community
  • 1
  • 1
myusuf
  • 11,810
  • 11
  • 35
  • 50
  • Thanks for the answer. Altought is a little cleaner approach I would like and approach where no code is needed in the controller. So every controller bootstraps with the method(s). – Juan Solano Sep 05 '14 at 15:30
  • I will keep looking and let you know when I find an answer. I am hopping @mikermcneil gives us some attention :D and enlighten us. – Juan Solano Sep 05 '14 at 15:33
  • I was thinking that maybe a hook would be a possibility, but since sails doesn't offer some kind of plug-in system, I don't feel confortable adding code directly to the npm module since it is .gitignored. Check this [hook](https://github.com/lucasconstantino/sails-hooks-seeds) for seeding database as a reference. – Juan Solano Sep 05 '14 at 15:44
0

I did mine as described here: OVERRIDE CRUD BLUEPRINTS.

I created the blueprint hooks in /api/blueprints/...

Community
  • 1
  • 1
Melvin
  • 5,798
  • 8
  • 46
  • 55
  • Thanks. But, is there a way to share the blueprint method to all controllers without specifying each and all in the config/routes.js?. I found out there are plugin api on the road. I hope we can achieve this then in a simple more modular way. http://t.co/TGdMws2sIj – Juan Solano Sep 13 '14 at 02:38