ruby 脚本中“rake routes"的结果 [英] Result of `rake routes` in ruby script

查看:27
本文介绍了ruby 脚本中“rake routes"的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rake routes 非常慢(在我的计算机中为 30 秒),但我需要它来进行路由规范.

rake routes is very slow (30s in my computer) but I need it for routing spec.

那么,有没有办法获得所有的路由,比如 rake 路由?(或者 rake 路由是如何工作的?)

So, is there a way to get all routes like rake routes? (or how rake routes works?)

我使用 Rails 3,我所看到的只是 Rails 3,我在 rails 文档中找不到任何可以使用的内容.

I use Rails 3 and all I have seen is for Rails 3, and I found nothing I can use in the rails doc.

推荐答案

Rails.application.routes.routes.to_a

.to_a 是可选的,它只是将其转换为数组.

.to_a is optional, it just converts it to an array.

(我在 railties/lib/rails/tasks/routes.rake 中找到了这一行)

(I found this line in railties/lib/rails/tasks/routes.rake)

我像这样使用它:routes[10].defaults => {:action=>"edit", :controller=>"polls"}

I use it like : routes[10].defaults => {:action=>"edit", :controller=>"polls"}

编辑:您可以在此处找到我执行路由规范的(相当笨拙的)方式:https://gist.github.com/52ac6d848ce0d9fd52ac

Edit : You can find the (quite hacky) way I do my routing specs here : https://gist.github.com/52ac6d848ce0d9fd52ac

这篇关于ruby 脚本中“rake routes"的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆