views:

49

answers:

2

Sorry for my english.

can I get all routes in my rails application? I need an output like rake routes and put the result in an array.

Is it possible?, how?

Thanks!

+4  A: 

You could have a look at way rails spits out those routes from the rake task. It's in /gems/rails/2.3.x/lib/tasks/routes.rake for Rails 2. Seems to be basically doing ActionController::Routing::Routes.routes in the general case and then interrogating that.

Shadwell
+2  A: 

Well, independently of where you need it, you could do:

routes = `rake routes`.split("\n")

Or even:

routes = `rake routes`.split("\n").map{ |r| r.gsub(', ', ',').split(' ') }
jordinl