Rafael Gomes Francisco
Rafael Gomes Francisco

Reputation: 2322

How can discover controller name and method from a path on Ruby on Rails?

Given a list of paths:

* /costumers/1
* /home
* /do/something/action-name

How can check the corresponding controller for these without need do the real call?


Context:

I have a spreadsheet with many routes (exported from application analytic [New Relic]). I'm try discover how routes doesn't are being called. This check does not be does programmatically.

I'm using rails 4.2

Thank's

Upvotes: 3

Views: 1558

Answers (1)

Schwern
Schwern

Reputation: 164679

You would do this with rails routes which will list all routes, verb, controller, and method.

You can search for certain routes with -g. rails routes -g /costumers for example. Don't search for /costumers/1. The 1 is not part of the route, it is the ID of the Costumer to show. Something like /costumers/:id. If your version does not support -g, pipe the output to grep rake routes | grep /costumers or use your pager rake routes | less.

You can also visit http://localhost:3000/rails/info/routes

See Rails Routing from the Outside In for more.

Upvotes: 6

Related Questions