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

141,318

Solution 1

rake routes

or

bundle exec rake routes

Solution 2

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

One more solution is

Rails.application.routes.routes

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

Solution 4

rails routes | grep <specific resource name>

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

Solution 5

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.

Share:
141,318

Related videos on Youtube

wael34218
Author by

wael34218

Updated on September 16, 2021

Comments

  • wael34218
    wael34218 over 2 years

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

    Thanks,

    • Mohsin Raza
      Mohsin Raza almost 8 years
      open your console and type rake routes
  • XåpplI'-I0llwlg'I  -
    XåpplI'-I0llwlg'I - over 8 years
    Furthermore, if you want to check whether a given path is recognized by your app's router, see this.
  • Dennis
    Dennis almost 8 years
    To state the obvious, this only works in development environment.
  • elc
    elc over 7 years
    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.
  • peter_v
    peter_v almost 5 years
    In a specific context, I had to use RAILS_ENV=dev /opt/rbenv/shims/bundle rake routes to make this work.
  • konyak
    konyak over 4 years
    Rails.application.routes.routes.map { |r| {alias: r.name, path: r.path.spec.to_s, controller: r.defaults[:controller], action: r.defaults[:action]}}
  • nekketsuuu
    nekketsuuu about 4 years
    rake routes is deprecated; use rails routes instead: github.com/rails/rails/pull/33660
  • smilingfrog
    smilingfrog over 2 years
    Rails.application.routes.routes.map(&:name).compact for just the named routes