Added '_path' to routes so you say Routes.bookings_path() instead of Routes.booking()

master
Adam Davies 2009-06-10 14:53:58 +09:30
parent ab7f7f1b53
commit 3c50f3c5ce
1 changed files with 7 additions and 7 deletions

View File

@ -196,7 +196,7 @@
protocol: window.location.protocol+'//',
host: window.location.hostname
};
Routes.extractNamed = function(){
var route;
for (var i = 0; i < this.length; i++) {
@ -204,20 +204,20 @@
if (route.name) {
this.named.push(route);
this.named[route.name] = route;
this[route.name] = (function(route){
this[route.name + '_path'] = (function(route){
var fn = function(){
var params = {},
options = {},
count;
//Add defaults from route
for (var p in route.params) {
if (route.params.hasOwnProperty(p) && route.params[p].constructor !== RegExp) {
params[p] = route.params[p];
}
}
//Allows Routes.name('foo', 'bar', {opts}) or Routes.name({foo:'foo', bar:'bar'}, {opts})
if (typeof arguments[0] === 'object' && !(arguments[0] instanceof Array)) {
extend(params, arguments[0]);
@ -226,7 +226,7 @@
if (typeof arguments[arguments.length-1] === 'object') {
options = arguments[arguments.length-1];
}
var count = 0;
for (var i=0; i < route.segments.length; i++) {
if (route.segments[i].isDynamic()) {
@ -235,7 +235,7 @@
}
}
}
return route.generate(params, options);
};