Rails 3: Get list of routes in namespace programmatically

后端 未结 2 1075
深忆病人
深忆病人 2020-12-15 08:38

Question

How can I get a list of all the routes in my Admin namespace so that I can use it in one of my tests?

Rationale

I frequentl

2条回答
  •  一个人的身影
    2020-12-15 09:15

    test_routes = []
    
    Rails.application.routes.routes.each do |route|
      route = route.path.spec.to_s
      test_routes << route if route.starts_with?('/admin')
    end
    

提交回复
热议问题