Rails 3: I want to list all paths defined in my rails application

Ruby on-RailsRuby on-Rails-3Routes

Ruby on-Rails Problem Overview


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

Thanks,

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

rake routes

or

bundle exec rake routes

Solution 2 - Ruby on-Rails

##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

Solution 3 - Ruby on-Rails

One more solution is

Rails.application.routes.routes

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

Solution 4 - Ruby on-Rails

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.

Solution 5 - Ruby on-Rails

rake routes | grep <specific resource name>

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

Solution 6 - Ruby on-Rails

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionwael34218View Question on Stackoverflow
Solution 1 - Ruby on-Railshouse9View Answer on Stackoverflow
Solution 2 - Ruby on-RailsAnwarView Answer on Stackoverflow
Solution 3 - Ruby on-RailsgayavatView Answer on Stackoverflow
Solution 4 - Ruby on-RailsDaniel HuffmanView Answer on Stackoverflow
Solution 5 - Ruby on-RailsWings2flyView Answer on Stackoverflow
Solution 6 - Ruby on-RailsAl DuncansonView Answer on Stackoverflow