182

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

Thanks,

1
  • open your console and type rake routes Commented Aug 1, 2016 at 10:26

7 Answers 7

276

new solution

rails routes

deprecated

rake routes

or

bundle exec rake routes
Sign up to request clarification or add additional context in comments.

4 Comments

Furthermore, if you want to check whether a given path is recognized by your app's router, see this.
In a specific context, I had to use RAILS_ENV=dev /opt/rbenv/shims/bundle rake routes to make this work.
rake routes is deprecated; use rails routes instead: github.com/rails/rails/pull/33660
localhost:3000/rails/info/routes Using this you can see all your routes in the UI
100

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

2 Comments

To state the obvious, this only works in development environment.
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.
38

One more solution is

Rails.application.routes.routes

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

2 Comments

Rails.application.routes.routes.map { |r| {alias: r.name, path: r.path.spec.to_s, controller: r.defaults[:controller], action: r.defaults[:action]}}
Rails.application.routes.routes.map(&:name).compact for just the named routes
14
rails routes | grep <specific resource name>

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

1 Comment

You can pass --grep directly to rails routes like: rails routes --grep "^/password"
10

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.

Comments

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

Comments

1

If you want to list them graphically or even simulate how a request runs through them, you can do this since Rails 3.2. There is the Rails.application.routes.router.visualizer

You can call it like this if you've got graphviz installed:

rails r 'File.write("./viz.html", Rails.application.routes.router.visualizer)'
ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 8080, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"
open "http://localhost:8080/viz.html"

Or if you just want to see a demo, have a look at the hosted example of tenderlove:

Visualized Rails routes

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.