Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How can you list all routes for a Rails application?

Decoding the http request TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.

Where are routes defined in Rails?

Best of all, Rails' Routing works with any web server. Routes are defined in app/config/routes. rb.

How many types of routes are there in Rails?

Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.

What are the 7 CRUD routes generated by the resources Method resources songs in Rails?

In Rails, there are seven standard CRUD actions: index, show, new, create, edit, update, and destroy, which relate to specific HTTP verbs and are usually implemented using specific ActiveRecord methods.


rake routes

or

bundle exec rake routes

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


One more solution is

Rails.application.routes.routes

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


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.


rake routes | grep <specific resource name>

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