Last Updated: February 25, 2016
·
930
· brain64bit

Displaying rails routes from console

Displaying rails routes from rails console / like sextant. Show HTTP Verbs, name, path and action, in development env, you can use Rails::Application::RouteInspector

inspector = Rails::Application::RouteInspector.new
inspector.collect_routes(Rails.application.routes.routes)

And in production :

Rails.application.routes.routes.map do |j|
    {
      path: "#{j.path.spec}.format", 
      verb: j.verb.inspect.gsub(/\W/, ""), 
      controller: j.defaults[:controller],
      action: j.defaults[:action]
    }
end