Posted By

insanedreamer on 07/10/10


Tagged

testing console rails3


Versions (?)

Inspect and test routes in console (Rails 3)


 / Published in: Rails
 

  1. r = Rails.application.routes
  2. ## MyApp::Application.routes does the same thing
  3.  
  4. # list all
  5.  
  6. r.routes.each { |x| puts x }
  7.  
  8. # inspect parts:
  9.  
  10. r1 = r.routes.first
  11. => GET areas:format {:action=>"index", :controller=>"areas"}
  12. r1.path
  13. => "/areas(.:format)"
  14. r1.requirements
  15. => {:action=>"index", :controller=>"areas"}
  16. r1.verb
  17. => "GET"
  18.  
  19. # test routes with:
  20.  
  21. r.recognize_path('/users')
  22. => {:action=>"index", :controller=>"users"}

Report this snippet  

You need to login to post a comment.