177

I want to list all defined helper path functions (that are created from routes) in my rails 3 application, if that is possible.

Thanks,

XåpplI'-I0llwlg'I -
  • 21,649
  • 28
  • 102
  • 151
wael34218
  • 4,860
  • 8
  • 44
  • 62

6 Answers6

262

new solution

rails routes

deprecated

rake routes

or

bundle exec rake routes
Kelvin Wang
  • 627
  • 5
  • 21
house9
  • 20,359
  • 8
  • 55
  • 61
98

Update

I later found that, there is an official way to see all the routes, by going to http://localhost:3000/rails/info/routes. Official docs: https://guides.rubyonrails.org/routing.html#listing-existing-routes


Though, it may be late, But I love the error page which displays all the routes. I usually try to go at /routes (or some bogus) path directly from the browser. Rails server automatically gives me a routing error page as well as all the routes and paths defined. That was very helpful :)

So, Just go to http://localhost:3000/routes enter image description here

Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
Anwar
  • 1,755
  • 1
  • 21
  • 32
  • 1
    To state the obvious, this only works in development environment. – Dennis Jun 28 '16 at 18:14
  • 7
    This is bundled into Rails 4, but the question asks about Rails 3. You'll need to install the Sextant gem to use this in 3. – elc Sep 06 '16 at 18:46
36

One more solution is

Rails.application.routes.routes

http://hackingoff.com/blog/generate-rails-sitemap-from-routes/

gayavat
  • 18,910
  • 11
  • 45
  • 55
  • 18
    `Rails.application.routes.routes.map { |r| {alias: r.name, path: r.path.spec.to_s, controller: r.defaults[:controller], action: r.defaults[:action]}}` – konyak Dec 05 '19 at 21:32
  • 1
    ```Rails.application.routes.routes.map(&:name).compact``` for just the named routes – smilingfrog Sep 13 '21 at 22:30
13
rails routes | grep <specific resource name>

displays resource specific routes, if it is a pretty long list of routes.

Sathish Manohar
  • 5,859
  • 10
  • 37
  • 47
Wings2fly
  • 887
  • 1
  • 11
  • 31
9

Trying http://0.0.0.0:3000/routes on a Rails 5 API app (i.e.: JSON-only oriented) will (as of Rails beta 3) return

{"status":404,"error":"Not Found","exception":"#> 
<ActionController::RoutingError:...

However, http://0.0.0.0:3000/rails/info/routes will render a nice, simple HTML page with routes.

Richard Erickson
  • 2,568
  • 8
  • 26
  • 39
7

CLI

updated for version 6

To list all existing routes you'll want to run the command:

bundle exec rails routes

bundle exec will

Execute a command in the context of the bundle

and rails routes will

list all of your defined routes

Example

If you have your resource route declared like so:

resource :credential, only: [:new, :create, :destroy]

Then it's helpful to pipe the output so you can grep for your specific resource.

For example: bundle exec rails routes grep example

Al Duncanson
  • 743
  • 9
  • 16