Skip to content

Commit

Permalink
Require controller to serve blueprint API.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Mar 26, 2013
1 parent ff84a4a commit 469ff2e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ function handler(req, res, next) {
// If a model exists, and the action is in the blueprint
if(qualifiedForBlueprint(requestedEntity, actionName)) {

// Use the JSON blueprint controller to return the appropriate CRUD action handler.
// Use the blueprint controller to return the appropriate CRUD action handler.
// (might actually use the view if one exists)
var blueprintController = require('./blueprints/controller').definition(requestedEntity);
var blueprintAction = blueprintController[actionName];
return runHandler(req, res, next, blueprintAction);
Expand Down Expand Up @@ -400,16 +401,17 @@ function isCrudAction(actionName) {
* Return whether the entity corresponds to an existing model
*/

function entityMatchesExistingModel(entity) {
return typeof sails.models[entity] !== "undefined";
function entityMatchesExistingModelAndController(entity) {
return typeof sails.models[entity] !== "undefined" &&
typeof sails.controllers[entity] !== "undefined";
}

/**
* Return whether this entity/action tuple qualifies to use blueprint methods
*/

function qualifiedForBlueprint(entity, action) {
return isCrudAction(action) && entityMatchesExistingModel(entity);
return isCrudAction(action) && entityMatchesExistingModelAndController(entity);
}


Expand Down

0 comments on commit 469ff2e

Please sign in to comment.