Dorian Dorian - 1 month ago 5
Ruby Question

Result of `rake routes` in ruby script

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

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

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

Answer

Rails.application.routes.routes.to_a

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

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

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

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

Comments