@@ -2213,23 +2213,23 @@ function! s:RailsFind()
22132213 return res
22142214endfunction
22152215
2216- function ! s: app_named_route_file (route) dict
2216+ function ! s: app_named_route_file (route) dict abort
22172217 call self .route_names ()
22182218 if self .cache.has (" named_routes" ) && has_key (self .cache.get (" named_routes" ),a: route )
2219- return self .cache.get (" named_routes" )[a: route ]
2219+ return s: sub ( self .cache.get (" named_routes" )[a: route ].handler, ' # ' , ' _controller.rb# ' )
22202220 endif
22212221 return " "
22222222endfunction
22232223
2224- function ! s: app_route_names () dict
2224+ function ! s: app_route_names () dict abort
22252225 if self .cache.needs (" named_routes" )
2226- let exec = " ActionController::Routing::Routes.named_routes.each {|n,r| puts %{#{n} #{r.requirements[:controller]}_controller.rb##{r.requirements[:action]}}}"
2227- let string = self .eval (exec )
22282226 let routes = {}
2229- for line in split (string ," \n " )
2230- let route = split (line ," " )
2231- let name = route[0 ]
2232- let routes[name] = route[1 ]
2227+ for line in split (system (self .rake_command ().' routes' ), " \n " )
2228+ let matches = matchlist (line , ' ^ \+\(\w\+\) \+\(\u\+\) \+\(\S\+\) \+\(\w\+#\w\+\)' )
2229+ if ! empty (matches)
2230+ let [_, name, method, path , handler; __] = matches
2231+ let routes[name] = {' method' : method, ' path' : path , ' handler' : handler}
2232+ endif
22332233 endfor
22342234 call self .cache.set (" named_routes" ,routes)
22352235 endif
@@ -2239,10 +2239,6 @@ endfunction
22392239
22402240call s: add_methods (' app' , [' route_names' ,' named_route_file' ])
22412241
2242- function ! RailsNamedRoutes ()
2243- return rails#app ().route_names ()
2244- endfunction
2245-
22462242function ! s: RailsIncludefind (str,... )
22472243 if a: str == # " ApplicationController"
22482244 return " application_controller.rb\n app/controllers/application.rb"
0 commit comments