Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add fallback helper name for better support "as" option

  • Loading branch information...
commit 08cb1fb6c2ccca0389c636ffec78e1b8830498d4 1 parent c2fdf6b
@1602 authored
Showing with 14 additions and 3 deletions.
  1. +3 −3 lib/railway_routes.js
  2. +11 −0 test/railway_routes_test.js
View
6 lib/railway_routes.js
@@ -103,20 +103,20 @@ Map.prototype.root = function (handler, middleware, options) {
action: action
});
- this.addPath(path, action);
+ this.addPath(path, action, options.as);
this.app[method].apply(this.app, args);
};
});
-Map.prototype.addPath = function (templatePath, action) {
+Map.prototype.addPath = function (templatePath, action, fallbackHelperName) {
if (templatePath instanceof RegExp) {
// TODO: think about adding to `path_to` routes by reg ex
return;
}
var paramsLength = templatePath.match(/\/:/g);
paramsLength = paramsLength === null ? 0 : paramsLength.length;
- var helperName = this.urlHelperName(templatePath, action);
+ var helperName = this.urlHelperName(templatePath, action) || fallbackHelperName;
// already defined? not need to redefine
if (this.pathTo[helperName]) return;
View
11 test/railway_routes_test.js
@@ -135,3 +135,14 @@ it('should handle root url', function (test) {
test.done();
});
+it('should allow to specify url helper name', function (test) {
+ var paths = [];
+ var map = new routes.Map(fakeApp(paths), fakeBridge());
+ map.get('/p/:id', 'posts#show', {as: 'post'});
+ test.deepEqual(paths, [
+ [ 'GET', '/p/:id', 'posts#show' ]
+ ]);
+ test.equal(map.pathTo.post(1), '/p/1');
+ test.done();
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.