ginad ginad - 6 months ago 34
Node.js Question

Is it possible to group controllers in sails using subfolders?

I'm planning to organize my controllers in sails using subfolder but I'm not sure how to do it. When I tried using like admin/PageController.js and connect it with the route I keep getting a 404 error.


You can definitely do this. The trick is, the controller identity is its path, in your case admin/PageController. So a custom route in config/routes.js would be something like:

'GET /admin/page/foo': 'admin/'

The great thing is, automatic actions still work, so if you have an index action in the controller then browsing to /admin/page will automatically run it.

You can also create controllers like this with sails generate controller admin/page.