Question

Is there a way in Rails to programmatically get all routes (derived from routes.rb) for a given resource? For example, if this is the resource defined in routes.rb--

  resources :survey_generation, only: [:index, :create]
  get "survey_generation/base_objects"

Is there a way for me to get the actions available on the survey_generation resource i.e. (index, create and base_objects)?

Edit: I want to do it programmatically in my code, not on the console using rake routes.

Was it helpful?

Solution

I think this fellow did what you want to do:

http://coryforsyth.com/2013/06/02/programmatically-list-routespaths-from-inside-your-rails-app/

If that's not quite right I'd still suggest doing what he did - look at the Rails source for the :routes rails task and work backward.

OTHER TIPS

This isn't really a proper answer as it could possibly give you more output than you'd like but the way I would do this is by using grep. Eg.

bundle exec rake routes | grep survey_generation
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top