Created
July 11, 2019 19:38
-
-
Save jamesgecko/8e812a10e47942306d9d193555ffaa45 to your computer and use it in GitHub Desktop.
Faster way to search Rails routes from the CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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