简体   繁体   中英

How to edit output of "rake routes"

I have a problem - how to edit output of command "rake routes"?

I got something like this:

在此处输入图片说明

It is ugly and unreadable. Any ideas how to change this output to more readable?

[EDIT] It is funny how I got these "minuses", but actually, noone has answered my question. I was asking about how to EDIT/MODIFY output of command "rake routes", not how to edit my terminal to show everything in one line. Of course, this is what I was looking for, partially, but it is not a good answer to my question.

I was looking for something like this:

stackoverflow.com/questions/20715385/how-to-format-rake-routes

but above solution doesnt work, maybe because it is quite old.

Still, if anyone knows answer to my question, that would be great to get it.

Have you tried accessing the HTML Routes view?

You can enable it adding this route get '/rails/info/routes' => 'routes' in your config/routes.rb file and then access the http://localhost:3000/rails/info/routes and you will see something like this:

在此处输入图片说明

You can grep your routes from the command line, like this:

For example, if you're looking for any route involving the word 'foobar'

rake routes | grep foobar

This is great if you just want quick output from the command line.

Here's a guide to GREP that I learned a lot from: https://www.maketecheasier.com/beginners-guide-to-grep/

Rails 6+

This is how you can edit the output of the command rails routes in the terminal.

Rails 6 introduced --expanded option.

Here is an example:

$ rails routes --expanded
--[ Route 1 ]------------------------------------------------------------
Prefix            | high_scores
Verb              | GET
URI               | /high_scores(.:format)
Controller#Action | high_scores#index
--[ Route 2 ]------------------------------------------------------------
Prefix            | new_high_score
Verb              | GET
URI               | /high_scores/new(.:format)
Controller#Action | high_scores#new
--[ Route 3 ]------------------------------------------------------------
Prefix            | blog
Verb              |
URI               | /blog
Controller#Action | Blog::Engine

[ Routes for Blog::Engine ]
--[ Route 1 ]------------------------------------------------------------
Prefix            | cart
Verb              | GET
URI               | /cart(.:format)
Controller#Action | cart#show

And a link to PR .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM