Skip to content
Browse files

Implemented singleton routes. map.resources('account', {singleton_for…

…:'users'})
  • Loading branch information...
1 parent 6f05378 commit bd896253ea03b6d067bb33a2dbedfcfd3472ce78 @olalonde olalonde committed Oct 4, 2012
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/railway_routes.js
View
15 lib/railway_routes.js
@@ -260,12 +260,14 @@ Map.prototype.resources = function (name, params, actions) {
// params.path setting allows to override common path component
var effectivePath = (params.path || name) + path;
+ var controller = (params.singleton_for) ? params.singleton_for : name;
+
// and call map.{get|post|update|delete}
// with the path, controller, middleware and options
this[method.toLowerCase()].call(
this,
effectivePath,
- name + '#' + action,
+ controller + '#' + action,
skipMiddleware ? [] : params.middleware,
getParams(action, params)
);
@@ -283,8 +285,19 @@ Map.prototype.resources = function (name, params, actions) {
, 'destroy': 'DELETE /:id'
, 'update': 'PUT /:id'
, 'show': 'GET /:id'
+ },
+ availableRoutesSingleton =
+ { 'show': 'GET /'
+ , 'create': 'POST /'
+ , 'new': 'GET /new'
+ , 'edit': 'GET /edit'
+ , 'destroy': 'DELETE /'
+ , 'update': 'PUT /'
};
+ if(params.singleton_for)
+ availableRoutes = availableRoutesSingleton;
+
// 1. only
if (params.only) {
if (typeof params.only == 'string') {

0 comments on commit bd89625

Please sign in to comment.
Something went wrong with that request. Please try again.