Skip to content

Instantly share code, notes, and snippets.

@jamesgecko

jamesgecko/routes

Created Jul 11, 2019
Embed
What would you like to do?
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