Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
List all of the routes in your Ruby on Rails application in a nicely-formatted HTML table. Well-suited to those times when you're building an API and need an "auto-updating" reference page of application endpoints that you can share with others.
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="//" rel="stylesheet">
<h1 style="text-align: center; margin-bottom: 20px;">Routes</h1>
<table class="table table-striped table-hover">
<th style="width: 45%;">Path</th>
<th style="width: 10%;">Verb</th>
<th style="width: 45%;">Controller#Action</th>
<% Rails.application.routes.routes.each do |route| %>
<% path = route.path.ast() %>
<% verb = route.verb.source %>
<% verb = verb[1..(verb.length-2)] if verb %>
<% controller = route.requirements[:controller] %>
<% action = route.requirements[:action] %>
<td><%= path %></td>
<td><%= verb %></td>
<td><%= controller %>&#35;<%= action %></td>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.