Skip to content

Commit 47336ac

Browse files
committed
Fix named route scraping
1 parent 64f693c commit 47336ac

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

autoload/rails.vim

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,23 +2213,23 @@ function! s:RailsFind()
22132213
return res
22142214
endfunction
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 ""
22222222
endfunction
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

22402240
call s:add_methods('app', ['route_names','named_route_file'])
22412241

2242-
function! RailsNamedRoutes()
2243-
return rails#app().route_names()
2244-
endfunction
2245-
22462242
function! s:RailsIncludefind(str,...)
22472243
if a:str ==# "ApplicationController"
22482244
return "application_controller.rb\napp/controllers/application.rb"

0 commit comments

Comments
 (0)