Ruby-on-rails Rails 3:我想列出在我的 rails 应用程序中定义的所有路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6798521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails 3: I want to list all paths defined in my rails application
提问by wael34218
I want to list all defined helper path functions (that are created from routes) in my rails 3 application, if that is possible.
如果可能的话,我想在我的 rails 3 应用程序中列出所有定义的辅助路径函数(从路由创建的)。
Thanks,
谢谢,
回答by house9
rake routes
or
或者
bundle exec rake routes
回答by Anwar
Update
更新
I later found that, there is an official way to see all the routes, by going to http://localhost:3000/rails/info/routes. Official docs: https://guides.rubyonrails.org/routing.html#listing-existing-routes
后来我发现,有一种官方的方法可以查看所有路由,通过访问http://localhost:3000/rails/info/routes。官方文档:https: //guides.rubyonrails.org/routing.html#listing-existing-routes
Though, it may be late, But I love the error page which displays all the routes. I usually try to go at /routes(or some bogus) path directly from the browser. Rails server automatically gives me a routing error page as well as all the routes and paths defined. That was very helpful :)
虽然,可能会晚,但我喜欢显示所有路线的错误页面。我通常尝试/routes直接从浏览器进入(或一些虚假的)路径。Rails 服务器自动给我一个路由错误页面以及所有定义的路由和路径。那很有帮助:)
So, Just go to http://localhost:3000/routes
所以,只需转到http://localhost:3000/routes
回答by gayavat
One more solution is
另一种解决方案是
Rails.application.routes.routes
http://hackingoff.com/blog/generate-rails-sitemap-from-routes/
http://hackingoff.com/blog/generate-rails-sitemap-from-routes/
回答by Daniel Huffman
Trying http://0.0.0.0:3000/routeson a Rails 5 API app (i.e.: JSON-only oriented) will (as of Rails beta 3) return
尝试http://0.0.0.0:3000/routes使用 Rails 5 API 应用程序(即:仅面向 JSON)将(从 Rails beta 3 开始)返回
{"status":404,"error":"Not Found","exception":"#>
<ActionController::RoutingError:...
However, http://0.0.0.0:3000/rails/info/routeswill render a nice, simple HTML page with routes.
但是,http://0.0.0.0:3000/rails/info/routes将呈现带有路由的漂亮、简单的 HTML 页面。
回答by Wings2fly
rake routes | grep <specific resource name>
displays resource specific routes, if it is a pretty long list of routes.
显示资源特定的路由,如果它是一个很长的路由列表。

