views:

107

answers:

2

Sammy.js is a controller library in javascript. But sometimes we have a 404 because our route doesn't seems to be valid to sammy.

How to know which route are defined by Sammy.js in a page ?

Something like the ruby on rails' rake routes.

Like answers we can search on app.routes. So I have something like in coffee script :

jQuery.each app.routes, (r) ->
  console.log(JSON.stringify(r))
  jQuery.each app.routes[r], (u) ->
    console.log(JSON.stringify(u))

or in JS

jQuery.each(app.routes, function(r) {
  console.log(JSON.stringify(r));
  return jQuery.each(app.routes[r], function(u) {
    return console.log(JSON.stringify(u));
  });
});

But it's not output the good routes I have in output :

"get"
0
1
"post"
0
1
2
etc...

So which code to do ?

+1  A: 

RTC: routes are added to app.routes, just write an accessor which return an iterator on it.

ook
I really don't success to read some Javascript code :(
shingara
You right, but it's more complicated like that because the routes is an Hash with key verb and value URL
shingara
I update with a starting of answer but doesn't works :(
shingara
+1  A: 

You can try something like that

var app = $.sammy.apps['body'];

jQuery.each(app.routes, function(verb, routes) {
  jQuery.each(routes, function(i, route) {
    console.log(route.verb, route.path);
  });
});
François
it's works like a charm, thanks a lot
shingara