Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print message on stderr when no routes are defined. #9316

Merged
merged 1 commit into from Feb 19, 2013

Conversation

steveklabnik
Copy link
Member

Newbies get confused when they run 'rake routes' and no routes are defined. Let's
point them to some documentation.

Thanks to @burtlo for the suggestion.

$ 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

routes

@steveklabnik
Copy link
Member Author

Added all the feedback @jeremy gave me.

We don't seem to have any tests on the HTML format, so I didn't write a new one... is it worth it? Also, the linkify helper is a bit... yeah. But given that this is the only place it's currently used, should be fine.

Any other thoughts, or should I :shipit: ?

@josevalim
Copy link
Contributor

Wouldn't it make more sense to just call formatter.no_routes and the formatter will generate the error message and show in the most appropriate format? This seems to be doing a lot of work and it would be easier/simpler to generate each message by hand.

@steveklabnik
Copy link
Member Author

@josevalim yeah, especially since this is only happening in two places. I dig it. Changing!

@steveklabnik
Copy link
Member Author

Much cleaner, @josevalim. Good call. That's what happens when you start one place and end up another...

@@ -90,6 +90,12 @@ def format(formatter, filter = nil)
routes_to_display = filter_routes(filter)

routes = collect_routes(routes_to_display)

unless routes.any?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if routes.none? looks simpler for me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always forget about none. I agree.

@burtlo
Copy link

burtlo commented Feb 18, 2013

👍 I approve this message.

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.
@steveklabnik
Copy link
Member Author

@fxn fixed per your comments.

@fxn
Copy link
Member

fxn commented Feb 19, 2013

Looks good to me, the space before the period hurts my eyes but it is easier that I edit later, good to go!

fxn added a commit that referenced this pull request Feb 19, 2013
Print message on stderr when no routes are defined.
@fxn fxn merged commit 33310fb into rails:master Feb 19, 2013
For more information about routes, see the Rails Guide: http://guides.rubyonrails.org/routing.html .
MESSAGE
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y U NO USE #strip_heredoc 😢

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what that is.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[2] pry(main)> def hello_world
[2] pry(main)*   <<-STR.strip_heredoc
[2] pry(main)*     win
[2] pry(main)*   STR
[2] pry(main)* end  
=> nil
[3] pry(main)> hello_world
=> "win\n"

@steveklabnik

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR this was fixed in 13c9195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants