Inspect and test routes in console (Rails 3)


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.