routes_with_names.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #---
  2. # Excerpted from "Agile Web Development with Rails",
  3. # published by The Pragmatic Bookshelf.
  4. # Copyrights apply to this code. It may not be used to create training material,
  5. # courses, books, articles, and the like. Contact us if you are in doubt.
  6. # We make no guarantees that this code is fit for any purpose.
  7. # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
  8. #---
  9. #---
  10. # Excerpted from "Agile Web Development with Rails, 4rd Ed.",
  11. # published by The Pragmatic Bookshelf.
  12. # Copyrights apply to this code. It may not be used to create training material,
  13. # courses, books, articles, and the like. Contact us if you are in doubt.
  14. # We make no guarantees that this code is fit for any purpose.
  15. # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
  16. #---
  17. ActionController::Routing::Routes.draw do |map|
  18. # Straight 'http://my.app/blog/' displays the index
  19. map.index "blog/",
  20. :controller => "blog",
  21. :action => "index"
  22. # Return articles for a year, year/month, or year/month/day
  23. map.date "blog/:year/:month/:day",
  24. :controller => "blog",
  25. :action => "show_date",
  26. :requirements => { :year => /(19|20)\d\d/,
  27. :month => /[01]?\d/,
  28. :day => /[0-3]?\d/},
  29. :day => nil,
  30. :month => nil
  31. # Show an article identified by an id
  32. map.show_article "blog/show/:id",
  33. :controller => "blog",
  34. :action => "show",
  35. :id => /\d+/
  36. # Regular Rails routing for admin stuff
  37. map.blog_admin "blog/:controller/:action/:id"
  38. # Catchall so we can gracefully handle badly formed requests
  39. map.catch_all "*anything",
  40. :controller => "blog",
  41. :action => "unknown_request"
  42. end