Skip to content

Instantly share code, notes, and snippets.

@jamesgecko
Created July 11, 2019 19:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesgecko/8e812a10e47942306d9d193555ffaa45 to your computer and use it in GitHub Desktop.
Save jamesgecko/8e812a10e47942306d9d193555ffaa45 to your computer and use it in GitHub Desktop.
Faster way to search Rails routes from the CLI
#! /usr/bin/env ruby
# Setup:
# Put this script in your path and make it executable.
# gem install nokogiri
#
# Usage:
# $ routes | grep index
require 'rubygems'
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open("http://callrail.test/rails/info/routes"))
page.css('tr').each do |route|
cells = route.css('td')
if cells.count == 4
route = [
cells[0]['data-route-name'],
cells[1]['data-route-verb'],
cells[2]['data-route-path'],
cells[3]['data-route-reqs']
]
puts "#{route[0]}\t#{route[1]}\t#{route[2]}\t#{route[3]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment