Skip to content

Commit

Permalink
Make sure to define the routes in express in a specific order.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbeardsley committed Jun 12, 2011
1 parent b724a9c commit 670453a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions index.js
Expand Up @@ -13,8 +13,17 @@
var express = require('express')
, join = require('path').join
, lingo = require('lingo')
, en = lingo.en;

, en = lingo.en
, orderedActions = [
'index' // GET /
,'new' // GET /new
,'create' // POST /
,'show' // GET /:id
,'edit' // GET /edit/:id
,'update' // PUT /:id
,'destroy'// DEL /:id
];

/**
* Initialize a new `Resource` with the given `name` and `actions`.
*
Expand All @@ -36,8 +45,10 @@ var Resource = module.exports = function Resource(name, actions, app) {
this.param = ':' + this.id;

// default actions
for (var key in actions) {
this.mapDefaultAction(key, actions[key]);
for(var i=0, key; i < orderedActions.length; i++) {
key = orderedActions[i];
if(actions[key])
this.mapDefaultAction(key, actions[key]);
}

// auto-loader
Expand Down

0 comments on commit 670453a

Please sign in to comment.