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.
This commit is contained in:
parent
8fd17e0c41
commit
d3b836ac4a
@ -1,5 +1,11 @@
|
||||
## Rails 4.0.0 (unreleased) ##
|
||||
|
||||
* Add a message when you have no routes defined to both `rake routes` and
|
||||
GET "/rails/info/routes" that lets you know you have none defined and links
|
||||
to the Rails Guide on the topic.
|
||||
|
||||
*Steve Klabnik*
|
||||
|
||||
* Change `image_alt` method to replace underscores/hyphens to spaces in filenames.
|
||||
|
||||
Previously, underscored filenames became `alt="A_long_file_name_with_underscores"`
|
||||
|
@ -91,6 +91,11 @@ def format(formatter, filter = nil)
|
||||
|
||||
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 @@ def header(routes)
|
||||
@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 @@ def section(routes)
|
||||
@buffer << @view.render(partial: "routes/route", collection: routes)
|
||||
end
|
||||
|
||||
def no_routes
|
||||
@buffer << <<-MESSAGE
|
||||
<p>You don't have any routes defined!</p>
|
||||
<ul>
|
||||
<li>Please add some routes in config/routes.rb.</li>
|
||||
<li>For more information about routes, please <a href="http://guides.rubyonrails.org/routing.html">see the Rails Guide</a>.</li>
|
||||
</ul>
|
||||
MESSAGE
|
||||
end
|
||||
|
||||
def result
|
||||
@view.raw @view.render(layout: "routes/table") {
|
||||
@view.raw @buffer.join("\n")
|
||||
|
@ -143,6 +143,21 @@ def test_rake_routes_calls_the_route_inspector
|
||||
assert_equal "cart GET /cart(.:format) cart#show\n", Dir.chdir(app_path){ `rake routes` }
|
||||
end
|
||||
|
||||
def test_rake_routes_displays_message_when_no_routes_are_defined
|
||||
app_file "config/routes.rb", <<-RUBY
|
||||
AppTemplate::Application.routes.draw do
|
||||
end
|
||||
RUBY
|
||||
|
||||
assert_equal <<-MESSAGE, Dir.chdir(app_path){ `rake routes` }
|
||||
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
|
||||
|
||||
def test_logger_is_flushed_when_exiting_production_rake_tasks
|
||||
add_to_config <<-RUBY
|
||||
rake_tasks do
|
||||
|
Loading…
Reference in New Issue
Block a user