Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add fallback helper name for better support "as" option

  • Loading branch information...
commit 08cb1fb6c2ccca0389c636ffec78e1b8830498d4 1 parent c2fdf6b
Anatoliy Chakkaev authored January 29, 2012
6  lib/railway_routes.js
@@ -103,20 +103,20 @@ Map.prototype.root = function (handler, middleware, options) {
103 103
             action: action
104 104
         });
105 105
 
106  
-        this.addPath(path, action);
  106
+        this.addPath(path, action, options.as);
107 107
 
108 108
         this.app[method].apply(this.app, args);
109 109
     };
110 110
 });
111 111
 
112  
-Map.prototype.addPath = function (templatePath, action) {
  112
+Map.prototype.addPath = function (templatePath, action, fallbackHelperName) {
113 113
     if (templatePath instanceof RegExp) {
114 114
         // TODO: think about adding to `path_to` routes by reg ex
115 115
         return;
116 116
     }
117 117
     var paramsLength = templatePath.match(/\/:/g);
118 118
     paramsLength = paramsLength === null ? 0 : paramsLength.length;
119  
-    var helperName = this.urlHelperName(templatePath, action);
  119
+    var helperName = this.urlHelperName(templatePath, action) || fallbackHelperName;
120 120
 
121 121
     // already defined? not need to redefine
122 122
     if (this.pathTo[helperName]) return;
11  test/railway_routes_test.js
@@ -135,3 +135,14 @@ it('should handle root url', function (test) {
135 135
     test.done();
136 136
 });
137 137
 
  138
+it('should allow to specify url helper name', function (test) {
  139
+    var paths = [];
  140
+    var map = new routes.Map(fakeApp(paths), fakeBridge());
  141
+    map.get('/p/:id', 'posts#show', {as: 'post'});
  142
+    test.deepEqual(paths, [
  143
+        [ 'GET', '/p/:id', 'posts#show' ]
  144
+    ]);
  145
+    test.equal(map.pathTo.post(1), '/p/1');
  146
+    test.done();
  147
+});
  148
+

0 notes on commit 08cb1fb

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