From d3b836ac4a35c1599be1fea0b72d5f19a9a37d4e Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 18 Feb 2013 10:26:59 -0800 Subject: Add message when you have no routes defined. Print a message in both `rake routes` and at GET "/rails/info/routes" that lets you know you have no routes defined, as well as linking to the Rails Guide on the topic. --- .../lib/action_dispatch/routing/inspector.rb | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb index 82dd05a802..d55c73269c 100644 --- a/actionpack/lib/action_dispatch/routing/inspector.rb +++ b/actionpack/lib/action_dispatch/routing/inspector.rb @@ -91,6 +91,11 @@ module ActionDispatch routes = collect_routes(routes_to_display) + if routes.none? + formatter.no_routes + return formatter.result + end + formatter.header routes formatter.section routes @@ -161,6 +166,16 @@ module ActionDispatch @buffer << draw_header(routes) end + def no_routes + @buffer << <<-MESSAGE +You don't have any routes defined! + +Please add some routes in config/routes.rb. + +For more information about routes, see the Rails Guide: http://guides.rubyonrails.org/routing.html . +MESSAGE + end + private def draw_section(routes) name_width, verb_width, path_width = widths(routes) @@ -197,6 +212,16 @@ module ActionDispatch @buffer << @view.render(partial: "routes/route", collection: routes) end + def no_routes + @buffer << <<-MESSAGE +

You don't have any routes defined!

+ +MESSAGE + end + def result @view.raw @view.render(layout: "routes/table") { @view.raw @buffer.join("\n") -- cgit v1.2.3