aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb
diff options
context:
space:
mode:
authorWinston <winston.yongwei@gmail.com>2014-04-06 18:03:15 +0800
committerWinston <winston.yongwei@gmail.com>2014-04-11 17:09:00 +0800
commit976495c787232fabcd860c1e1786f1e213f2f998 (patch)
tree3290d8f477e62ce4985bd17403eec9ead3f93016 /actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb
parent856ffbe7058065a34a708fd5b398c0553f9f1f97 (diff)
downloadrails-976495c787232fabcd860c1e1786f1e213f2f998.tar.gz
rails-976495c787232fabcd860c1e1786f1e213f2f998.tar.bz2
rails-976495c787232fabcd860c1e1786f1e213f2f998.zip
Implement fuzzy matching for route search on routing error html page.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb18
1 files changed, 10 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb b/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb
index 323873ba4b..6ee48f95ea 100644
--- a/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb
@@ -88,13 +88,15 @@
});
}
- // takes an array of elements with a data-regexp attribute and
+ // Takes an array of elements with a data-regexp attribute and
// passes their parent <tr> into the callback function
- // if the regexp matches a given path
- function eachElemsForPath(elems, path, func) {
+ // if the user input fuzzy matches a route or if the regexp matches a given path
+ function eachElemsForPath(elems, value, func) {
+ var path = sanitizePath(value);
each(elems, function(e){
- var reg = e.getAttribute("data-regexp");
- if (path.match(RegExp(reg))) {
+ var route = e.getAttribute("data-route-path"),
+ regexp = e.getAttribute("data-regexp");
+ if (route.match(RegExp(value)) || path.match(RegExp(regexp))) {
func(e.parentNode.cloneNode(true));
}
})
@@ -121,14 +123,14 @@
// On key press perform a search for matching paths
pathElem.onkeyup = function(e){
- var path = sanitizePath(pathElem.value),
- defaultText = '<tr><th colspan="4">Paths Matching (' + path + '):</th></tr>';
+ var userInput = pathElem.value,
+ defaultText = '<tr><th colspan="4">Paths Matching (' + userInput +'):</th></tr>';
// Clear out results section
selectedSection.innerHTML= defaultText;
// Display matches if they exist
- eachElemsForPath(regexpElems, path, function(e){
+ eachElemsForPath(regexpElems, userInput, function(e){
selectedSection.appendChild(e);
});