openskies 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (494) hide show
  1. data/CHANGELOG.md +87 -0
  2. data/README.rdoc +35 -0
  3. data/bin/openskies +9 -0
  4. data/guides/assets/images/belongs_to.png +0 -0
  5. data/guides/assets/images/book_icon.gif +0 -0
  6. data/guides/assets/images/bullet.gif +0 -0
  7. data/guides/assets/images/challenge.png +0 -0
  8. data/guides/assets/images/chapters_icon.gif +0 -0
  9. data/guides/assets/images/check_bullet.gif +0 -0
  10. data/guides/assets/images/credits_pic_blank.gif +0 -0
  11. data/guides/assets/images/csrf.png +0 -0
  12. data/guides/assets/images/customized_error_messages.png +0 -0
  13. data/guides/assets/images/edge_badge.png +0 -0
  14. data/guides/assets/images/error_messages.png +0 -0
  15. data/guides/assets/images/feature_tile.gif +0 -0
  16. data/guides/assets/images/footer_tile.gif +0 -0
  17. data/guides/assets/images/fxn.png +0 -0
  18. data/guides/assets/images/grey_bullet.gif +0 -0
  19. data/guides/assets/images/habtm.png +0 -0
  20. data/guides/assets/images/has_many.png +0 -0
  21. data/guides/assets/images/has_many_through.png +0 -0
  22. data/guides/assets/images/has_one.png +0 -0
  23. data/guides/assets/images/has_one_through.png +0 -0
  24. data/guides/assets/images/header_backdrop.png +0 -0
  25. data/guides/assets/images/header_tile.gif +0 -0
  26. data/guides/assets/images/i18n/demo_html_safe.png +0 -0
  27. data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
  28. data/guides/assets/images/i18n/demo_translated_en.png +0 -0
  29. data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
  30. data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
  31. data/guides/assets/images/i18n/demo_untranslated.png +0 -0
  32. data/guides/assets/images/icons/README +5 -0
  33. data/guides/assets/images/icons/callouts/1.png +0 -0
  34. data/guides/assets/images/icons/callouts/10.png +0 -0
  35. data/guides/assets/images/icons/callouts/11.png +0 -0
  36. data/guides/assets/images/icons/callouts/12.png +0 -0
  37. data/guides/assets/images/icons/callouts/13.png +0 -0
  38. data/guides/assets/images/icons/callouts/14.png +0 -0
  39. data/guides/assets/images/icons/callouts/15.png +0 -0
  40. data/guides/assets/images/icons/callouts/2.png +0 -0
  41. data/guides/assets/images/icons/callouts/3.png +0 -0
  42. data/guides/assets/images/icons/callouts/4.png +0 -0
  43. data/guides/assets/images/icons/callouts/5.png +0 -0
  44. data/guides/assets/images/icons/callouts/6.png +0 -0
  45. data/guides/assets/images/icons/callouts/7.png +0 -0
  46. data/guides/assets/images/icons/callouts/8.png +0 -0
  47. data/guides/assets/images/icons/callouts/9.png +0 -0
  48. data/guides/assets/images/icons/caution.png +0 -0
  49. data/guides/assets/images/icons/example.png +0 -0
  50. data/guides/assets/images/icons/home.png +0 -0
  51. data/guides/assets/images/icons/important.png +0 -0
  52. data/guides/assets/images/icons/next.png +0 -0
  53. data/guides/assets/images/icons/note.png +0 -0
  54. data/guides/assets/images/icons/prev.png +0 -0
  55. data/guides/assets/images/icons/tip.png +0 -0
  56. data/guides/assets/images/icons/up.png +0 -0
  57. data/guides/assets/images/icons/warning.png +0 -0
  58. data/guides/assets/images/jaimeiniesta.jpg +0 -0
  59. data/guides/assets/images/nav_arrow.gif +0 -0
  60. data/guides/assets/images/polymorphic.png +0 -0
  61. data/guides/assets/images/posts_index.png +0 -0
  62. data/guides/assets/images/radar.png +0 -0
  63. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  64. data/guides/assets/images/rails_guides_logo.gif +0 -0
  65. data/guides/assets/images/rails_logo_remix.gif +0 -0
  66. data/guides/assets/images/rails_welcome.png +0 -0
  67. data/guides/assets/images/session_fixation.png +0 -0
  68. data/guides/assets/images/tab_grey.gif +0 -0
  69. data/guides/assets/images/tab_info.gif +0 -0
  70. data/guides/assets/images/tab_note.gif +0 -0
  71. data/guides/assets/images/tab_red.gif +0 -0
  72. data/guides/assets/images/tab_yellow.gif +0 -0
  73. data/guides/assets/images/tab_yellow.png +0 -0
  74. data/guides/assets/images/validation_error_messages.png +0 -0
  75. data/guides/assets/images/vijaydev.jpg +0 -0
  76. data/guides/assets/javascripts/guides.js +7 -0
  77. data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
  78. data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
  79. data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
  80. data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
  81. data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
  82. data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
  83. data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
  84. data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
  85. data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
  86. data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
  87. data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
  88. data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
  89. data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
  90. data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
  91. data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
  92. data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
  93. data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
  94. data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
  95. data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
  96. data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
  97. data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
  98. data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
  99. data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
  100. data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
  101. data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
  102. data/guides/assets/javascripts/syntaxhighlighter/shCore.js +17 -0
  103. data/guides/assets/stylesheets/fixes.css +16 -0
  104. data/guides/assets/stylesheets/kindle.css +11 -0
  105. data/guides/assets/stylesheets/main.css +453 -0
  106. data/guides/assets/stylesheets/print.css +52 -0
  107. data/guides/assets/stylesheets/reset.css +43 -0
  108. data/guides/assets/stylesheets/style.css +13 -0
  109. data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +226 -0
  110. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
  111. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
  112. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
  113. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
  114. data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
  115. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
  116. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
  117. data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
  118. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
  119. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
  120. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
  121. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
  122. data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
  123. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
  124. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
  125. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
  126. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
  127. data/guides/code/getting_started/Gemfile +38 -0
  128. data/guides/code/getting_started/README.rdoc +261 -0
  129. data/guides/code/getting_started/Rakefile +7 -0
  130. data/guides/code/getting_started/app/assets/images/rails.png +0 -0
  131. data/guides/code/getting_started/app/assets/javascripts/application.js +15 -0
  132. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
  133. data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +3 -0
  134. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
  135. data/guides/code/getting_started/app/assets/stylesheets/application.css +13 -0
  136. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
  137. data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +3 -0
  138. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
  139. data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +56 -0
  140. data/guides/code/getting_started/app/controllers/application_controller.rb +3 -0
  141. data/guides/code/getting_started/app/controllers/comments_controller.rb +16 -0
  142. data/guides/code/getting_started/app/controllers/home_controller.rb +5 -0
  143. data/guides/code/getting_started/app/controllers/posts_controller.rb +84 -0
  144. data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
  145. data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
  146. data/guides/code/getting_started/app/helpers/home_helper.rb +2 -0
  147. data/guides/code/getting_started/app/helpers/posts_helper.rb +5 -0
  148. data/guides/code/getting_started/app/models/comment.rb +3 -0
  149. data/guides/code/getting_started/app/models/post.rb +11 -0
  150. data/guides/code/getting_started/app/models/tag.rb +3 -0
  151. data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
  152. data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
  153. data/guides/code/getting_started/app/views/home/index.html.erb +2 -0
  154. data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
  155. data/guides/code/getting_started/app/views/posts/_form.html.erb +32 -0
  156. data/guides/code/getting_started/app/views/posts/edit.html.erb +6 -0
  157. data/guides/code/getting_started/app/views/posts/index.html.erb +27 -0
  158. data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
  159. data/guides/code/getting_started/app/views/posts/show.html.erb +31 -0
  160. data/guides/code/getting_started/app/views/tags/_form.html.erb +12 -0
  161. data/guides/code/getting_started/config/application.rb +59 -0
  162. data/guides/code/getting_started/config/boot.rb +6 -0
  163. data/guides/code/getting_started/config/database.yml +25 -0
  164. data/guides/code/getting_started/config/environment.rb +5 -0
  165. data/guides/code/getting_started/config/environments/development.rb +37 -0
  166. data/guides/code/getting_started/config/environments/production.rb +67 -0
  167. data/guides/code/getting_started/config/environments/test.rb +37 -0
  168. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
  169. data/guides/code/getting_started/config/initializers/inflections.rb +15 -0
  170. data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
  171. data/guides/code/getting_started/config/initializers/secret_token.rb +7 -0
  172. data/guides/code/getting_started/config/initializers/session_store.rb +8 -0
  173. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
  174. data/guides/code/getting_started/config/locales/en.yml +5 -0
  175. data/guides/code/getting_started/config/routes.rb +64 -0
  176. data/guides/code/getting_started/config.ru +4 -0
  177. data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +11 -0
  178. data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +12 -0
  179. data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +11 -0
  180. data/guides/code/getting_started/db/schema.rb +43 -0
  181. data/guides/code/getting_started/db/seeds.rb +7 -0
  182. data/guides/code/getting_started/doc/README_FOR_APP +2 -0
  183. data/guides/code/getting_started/public/404.html +26 -0
  184. data/guides/code/getting_started/public/422.html +26 -0
  185. data/guides/code/getting_started/public/500.html +25 -0
  186. data/guides/code/getting_started/public/favicon.ico +0 -0
  187. data/guides/code/getting_started/public/robots.txt +5 -0
  188. data/guides/code/getting_started/script/rails +6 -0
  189. data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
  190. data/guides/code/getting_started/test/fixtures/posts.yml +11 -0
  191. data/guides/code/getting_started/test/fixtures/tags.yml +9 -0
  192. data/guides/code/getting_started/test/functional/comments_controller_test.rb +7 -0
  193. data/guides/code/getting_started/test/functional/home_controller_test.rb +9 -0
  194. data/guides/code/getting_started/test/functional/posts_controller_test.rb +49 -0
  195. data/guides/code/getting_started/test/performance/browsing_test.rb +12 -0
  196. data/guides/code/getting_started/test/test_helper.rb +13 -0
  197. data/guides/code/getting_started/test/unit/comment_test.rb +7 -0
  198. data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +4 -0
  199. data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +4 -0
  200. data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +4 -0
  201. data/guides/code/getting_started/test/unit/post_test.rb +7 -0
  202. data/guides/code/getting_started/test/unit/tag_test.rb +7 -0
  203. data/guides/rails_guides/generator.rb +310 -0
  204. data/guides/rails_guides/helpers.rb +45 -0
  205. data/guides/rails_guides/indexer.rb +69 -0
  206. data/guides/rails_guides/levenshtein.rb +31 -0
  207. data/guides/rails_guides/textile_extensions.rb +63 -0
  208. data/guides/rails_guides.rb +50 -0
  209. data/guides/source/2_2_release_notes.textile +422 -0
  210. data/guides/source/2_3_release_notes.textile +610 -0
  211. data/guides/source/3_0_release_notes.textile +595 -0
  212. data/guides/source/3_1_release_notes.textile +553 -0
  213. data/guides/source/3_2_release_notes.textile +540 -0
  214. data/guides/source/_license.html.erb +2 -0
  215. data/guides/source/_welcome.html.erb +19 -0
  216. data/guides/source/action_controller_overview.textile +820 -0
  217. data/guides/source/action_mailer_basics.textile +516 -0
  218. data/guides/source/action_view_overview.textile +1497 -0
  219. data/guides/source/active_model_basics.textile +205 -0
  220. data/guides/source/active_record_basics.textile +218 -0
  221. data/guides/source/active_record_querying.textile +1433 -0
  222. data/guides/source/active_record_validations_callbacks.textile +1283 -0
  223. data/guides/source/active_resource_basics.textile +120 -0
  224. data/guides/source/active_support_core_extensions.textile +3713 -0
  225. data/guides/source/ajax_on_rails.textile +267 -0
  226. data/guides/source/api_documentation_guidelines.textile +185 -0
  227. data/guides/source/asset_pipeline.textile +707 -0
  228. data/guides/source/association_basics.textile +1959 -0
  229. data/guides/source/caching_with_rails.textile +437 -0
  230. data/guides/source/command_line.textile +574 -0
  231. data/guides/source/configuring.textile +641 -0
  232. data/guides/source/contributing_to_ruby_on_rails.textile +448 -0
  233. data/guides/source/credits.html.erb +72 -0
  234. data/guides/source/debugging_rails_applications.textile +714 -0
  235. data/guides/source/documents.yaml +157 -0
  236. data/guides/source/engines.textile +618 -0
  237. data/guides/source/form_helpers.textile +798 -0
  238. data/guides/source/generators.textile +621 -0
  239. data/guides/source/getting_started.textile +1929 -0
  240. data/guides/source/i18n.textile +931 -0
  241. data/guides/source/index.html.erb +30 -0
  242. data/guides/source/initialization.textile +1116 -0
  243. data/guides/source/kindle/KINDLE.md +26 -0
  244. data/guides/source/kindle/copyright.html.erb +1 -0
  245. data/guides/source/kindle/layout.html.erb +27 -0
  246. data/guides/source/kindle/rails_guides.opf.erb +52 -0
  247. data/guides/source/kindle/toc.html.erb +24 -0
  248. data/guides/source/kindle/toc.ncx.erb +64 -0
  249. data/guides/source/kindle/welcome.html.erb +5 -0
  250. data/guides/source/layout.html.erb +124 -0
  251. data/guides/source/layouts_and_rendering.textile +1237 -0
  252. data/guides/source/migrations.textile +900 -0
  253. data/guides/source/nested_model_forms.textile +222 -0
  254. data/guides/source/performance_testing.textile +597 -0
  255. data/guides/source/plugins.textile +464 -0
  256. data/guides/source/rails_application_templates.textile +240 -0
  257. data/guides/source/rails_on_rack.textile +236 -0
  258. data/guides/source/routing.textile +885 -0
  259. data/guides/source/ruby_on_rails_guides_guidelines.textile +79 -0
  260. data/guides/source/security.textile +1004 -0
  261. data/guides/source/testing.textile +947 -0
  262. data/guides/w3c_validator.rb +91 -0
  263. data/lib/rails/all.rb +15 -0
  264. data/lib/rails/application/bootstrap.rb +73 -0
  265. data/lib/rails/application/configuration.rb +151 -0
  266. data/lib/rails/application/finisher.rb +98 -0
  267. data/lib/rails/application/railties.rb +13 -0
  268. data/lib/rails/application/route_inspector.rb +84 -0
  269. data/lib/rails/application/routes_reloader.rb +56 -0
  270. data/lib/rails/application.rb +320 -0
  271. data/lib/rails/backtrace_cleaner.rb +42 -0
  272. data/lib/rails/cli.rb +16 -0
  273. data/lib/rails/code_statistics.rb +118 -0
  274. data/lib/rails/commands/application.rb +38 -0
  275. data/lib/rails/commands/benchmarker.rb +34 -0
  276. data/lib/rails/commands/console.rb +55 -0
  277. data/lib/rails/commands/dbconsole.rb +123 -0
  278. data/lib/rails/commands/destroy.rb +10 -0
  279. data/lib/rails/commands/generate.rb +12 -0
  280. data/lib/rails/commands/plugin.rb +544 -0
  281. data/lib/rails/commands/plugin_new.rb +11 -0
  282. data/lib/rails/commands/profiler.rb +32 -0
  283. data/lib/rails/commands/runner.rb +54 -0
  284. data/lib/rails/commands/server.rb +100 -0
  285. data/lib/rails/commands/update.rb +9 -0
  286. data/lib/rails/commands.rb +104 -0
  287. data/lib/rails/configuration.rb +89 -0
  288. data/lib/rails/console/app.rb +36 -0
  289. data/lib/rails/console/helpers.rb +11 -0
  290. data/lib/rails/engine/commands.rb +43 -0
  291. data/lib/rails/engine/configuration.rb +84 -0
  292. data/lib/rails/engine/railties.rb +33 -0
  293. data/lib/rails/engine.rb +657 -0
  294. data/lib/rails/generators/actions.rb +325 -0
  295. data/lib/rails/generators/active_model.rb +78 -0
  296. data/lib/rails/generators/app_base.rb +281 -0
  297. data/lib/rails/generators/base.rb +390 -0
  298. data/lib/rails/generators/css/assets/assets_generator.rb +13 -0
  299. data/lib/rails/generators/css/assets/templates/stylesheet.css +4 -0
  300. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +16 -0
  301. data/lib/rails/generators/erb/controller/controller_generator.rb +20 -0
  302. data/lib/rails/generators/erb/controller/templates/view.html.erb +2 -0
  303. data/lib/rails/generators/erb/mailer/mailer_generator.rb +13 -0
  304. data/lib/rails/generators/erb/mailer/templates/view.text.erb +3 -0
  305. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +29 -0
  306. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +23 -0
  307. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +6 -0
  308. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +27 -0
  309. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +5 -0
  310. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +12 -0
  311. data/lib/rails/generators/erb.rb +21 -0
  312. data/lib/rails/generators/generated_attribute.rb +107 -0
  313. data/lib/rails/generators/js/assets/assets_generator.rb +13 -0
  314. data/lib/rails/generators/js/assets/templates/javascript.js +2 -0
  315. data/lib/rails/generators/migration.rb +68 -0
  316. data/lib/rails/generators/named_base.rb +202 -0
  317. data/lib/rails/generators/rails/app/USAGE +15 -0
  318. data/lib/rails/generators/rails/app/app_generator.rb +303 -0
  319. data/lib/rails/generators/rails/app/templates/Gemfile +26 -0
  320. data/lib/rails/generators/rails/app/templates/README +261 -0
  321. data/lib/rails/generators/rails/app/templates/Rakefile +7 -0
  322. data/lib/rails/generators/rails/app/templates/app/assets/images/rails.png +0 -0
  323. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +17 -0
  324. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +13 -0
  325. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +3 -0
  326. data/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb +2 -0
  327. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  328. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  329. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +14 -0
  330. data/lib/rails/generators/rails/app/templates/config/application.rb +74 -0
  331. data/lib/rails/generators/rails/app/templates/config/boot.rb +6 -0
  332. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +31 -0
  333. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +86 -0
  334. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +62 -0
  335. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +33 -0
  336. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +43 -0
  337. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +20 -0
  338. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +54 -0
  339. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +39 -0
  340. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +55 -0
  341. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +25 -0
  342. data/lib/rails/generators/rails/app/templates/config/environment.rb +5 -0
  343. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +41 -0
  344. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +73 -0
  345. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +39 -0
  346. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb +7 -0
  347. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +15 -0
  348. data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb +5 -0
  349. data/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +7 -0
  350. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +8 -0
  351. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +16 -0
  352. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +5 -0
  353. data/lib/rails/generators/rails/app/templates/config/routes.rb +58 -0
  354. data/lib/rails/generators/rails/app/templates/config.ru +4 -0
  355. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +7 -0
  356. data/lib/rails/generators/rails/app/templates/doc/README_FOR_APP +2 -0
  357. data/lib/rails/generators/rails/app/templates/gitignore +15 -0
  358. data/lib/rails/generators/rails/app/templates/public/404.html +26 -0
  359. data/lib/rails/generators/rails/app/templates/public/422.html +26 -0
  360. data/lib/rails/generators/rails/app/templates/public/500.html +25 -0
  361. data/lib/rails/generators/rails/app/templates/public/favicon.ico +0 -0
  362. data/lib/rails/generators/rails/app/templates/public/index.html +241 -0
  363. data/lib/rails/generators/rails/app/templates/public/robots.txt +5 -0
  364. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  365. data/lib/rails/generators/rails/app/templates/script/rails +5 -0
  366. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  367. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  368. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  369. data/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +12 -0
  370. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +15 -0
  371. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  372. data/lib/rails/generators/rails/assets/USAGE +20 -0
  373. data/lib/rails/generators/rails/assets/assets_generator.rb +25 -0
  374. data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
  375. data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
  376. data/lib/rails/generators/rails/controller/USAGE +18 -0
  377. data/lib/rails/generators/rails/controller/controller_generator.rb +20 -0
  378. data/lib/rails/generators/rails/controller/templates/controller.rb +13 -0
  379. data/lib/rails/generators/rails/generator/USAGE +12 -0
  380. data/lib/rails/generators/rails/generator/generator_generator.rb +25 -0
  381. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +3 -0
  382. data/lib/rails/generators/rails/generator/templates/USAGE.tt +8 -0
  383. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  384. data/lib/rails/generators/rails/helper/USAGE +17 -0
  385. data/lib/rails/generators/rails/helper/helper_generator.rb +13 -0
  386. data/lib/rails/generators/rails/helper/templates/helper.rb +4 -0
  387. data/lib/rails/generators/rails/integration_test/USAGE +10 -0
  388. data/lib/rails/generators/rails/integration_test/integration_test_generator.rb +7 -0
  389. data/lib/rails/generators/rails/migration/USAGE +29 -0
  390. data/lib/rails/generators/rails/migration/migration_generator.rb +8 -0
  391. data/lib/rails/generators/rails/model/USAGE +45 -0
  392. data/lib/rails/generators/rails/model/model_generator.rb +8 -0
  393. data/lib/rails/generators/rails/observer/USAGE +12 -0
  394. data/lib/rails/generators/rails/observer/observer_generator.rb +7 -0
  395. data/lib/rails/generators/rails/performance_test/USAGE +10 -0
  396. data/lib/rails/generators/rails/performance_test/performance_test_generator.rb +7 -0
  397. data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
  398. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +318 -0
  399. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +29 -0
  400. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +23 -0
  401. data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
  402. data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
  403. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +31 -0
  404. data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
  405. data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
  406. data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
  407. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  408. data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +14 -0
  409. data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
  410. data/lib/rails/generators/rails/plugin_new/templates/gitignore +7 -0
  411. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
  412. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb +3 -0
  413. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
  414. data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
  415. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +18 -0
  416. data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
  417. data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
  418. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +7 -0
  419. data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
  420. data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
  421. data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +15 -0
  422. data/lib/rails/generators/rails/resource/USAGE +23 -0
  423. data/lib/rails/generators/rails/resource/resource_generator.rb +20 -0
  424. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +50 -0
  425. data/lib/rails/generators/rails/scaffold/USAGE +35 -0
  426. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +23 -0
  427. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +56 -0
  428. data/lib/rails/generators/rails/scaffold_controller/USAGE +19 -0
  429. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +25 -0
  430. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +89 -0
  431. data/lib/rails/generators/rails/session_migration/USAGE +8 -0
  432. data/lib/rails/generators/rails/session_migration/session_migration_generator.rb +8 -0
  433. data/lib/rails/generators/rails/task/USAGE +9 -0
  434. data/lib/rails/generators/rails/task/task_generator.rb +12 -0
  435. data/lib/rails/generators/rails/task/templates/task.rb +8 -0
  436. data/lib/rails/generators/resource_helpers.rb +80 -0
  437. data/lib/rails/generators/test_case.rb +247 -0
  438. data/lib/rails/generators/test_unit/controller/controller_generator.rb +15 -0
  439. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +19 -0
  440. data/lib/rails/generators/test_unit/helper/helper_generator.rb +13 -0
  441. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +6 -0
  442. data/lib/rails/generators/test_unit/integration/integration_generator.rb +13 -0
  443. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +7 -0
  444. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +14 -0
  445. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +21 -0
  446. data/lib/rails/generators/test_unit/model/model_generator.rb +24 -0
  447. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +23 -0
  448. data/lib/rails/generators/test_unit/model/templates/unit_test.rb +9 -0
  449. data/lib/rails/generators/test_unit/observer/observer_generator.rb +13 -0
  450. data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +9 -0
  451. data/lib/rails/generators/test_unit/performance/performance_generator.rb +13 -0
  452. data/lib/rails/generators/test_unit/performance/templates/performance_test.rb +12 -0
  453. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +13 -0
  454. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +7 -0
  455. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +3 -0
  456. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +38 -0
  457. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +51 -0
  458. data/lib/rails/generators/test_unit.rb +8 -0
  459. data/lib/rails/generators.rb +339 -0
  460. data/lib/rails/info.rb +116 -0
  461. data/lib/rails/info_controller.rb +15 -0
  462. data/lib/rails/initializable.rb +89 -0
  463. data/lib/rails/paths.rb +211 -0
  464. data/lib/rails/performance_test_help.rb +3 -0
  465. data/lib/rails/plugin.rb +92 -0
  466. data/lib/rails/rack/debugger.rb +24 -0
  467. data/lib/rails/rack/log_tailer.rb +34 -0
  468. data/lib/rails/rack/logger.rb +60 -0
  469. data/lib/rails/rack.rb +7 -0
  470. data/lib/rails/railtie/configurable.rb +35 -0
  471. data/lib/rails/railtie/configuration.rb +90 -0
  472. data/lib/rails/railtie.rb +202 -0
  473. data/lib/rails/ruby_version_check.rb +23 -0
  474. data/lib/rails/rubyprof_ext.rb +35 -0
  475. data/lib/rails/script_rails_loader.rb +29 -0
  476. data/lib/rails/source_annotation_extractor.rb +104 -0
  477. data/lib/rails/tasks/annotations.rake +20 -0
  478. data/lib/rails/tasks/documentation.rake +155 -0
  479. data/lib/rails/tasks/engine.rake +72 -0
  480. data/lib/rails/tasks/framework.rake +76 -0
  481. data/lib/rails/tasks/log.rake +9 -0
  482. data/lib/rails/tasks/middleware.rake +7 -0
  483. data/lib/rails/tasks/misc.rake +67 -0
  484. data/lib/rails/tasks/routes.rake +9 -0
  485. data/lib/rails/tasks/statistics.rake +16 -0
  486. data/lib/rails/tasks/tmp.rake +37 -0
  487. data/lib/rails/tasks.rb +16 -0
  488. data/lib/rails/test_help.rb +56 -0
  489. data/lib/rails/test_unit/railtie.rb +15 -0
  490. data/lib/rails/test_unit/sub_test_task.rb +8 -0
  491. data/lib/rails/test_unit/testing.rake +146 -0
  492. data/lib/rails/version.rb +10 -0
  493. data/lib/rails.rb +126 -0
  494. metadata +609 -0
@@ -0,0 +1,885 @@
1
+ h2. Rails Routing from the Outside In
2
+
3
+ This guide covers the user-facing features of Rails routing. By referring to this guide, you will be able to:
4
+
5
+ * Understand the code in +routes.rb+
6
+ * Construct your own routes, using either the preferred resourceful style or the <tt>match</tt> method
7
+ * Identify what parameters to expect an action to receive
8
+ * Automatically create paths and URLs using route helpers
9
+ * Use advanced techniques such as constraints and Rack endpoints
10
+
11
+ endprologue.
12
+
13
+ h3. The Purpose of the Rails Router
14
+
15
+ The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.
16
+
17
+ h4. Connecting URLs to Code
18
+
19
+ When your Rails application receives an incoming request
20
+
21
+ <plain>
22
+ GET /patients/17
23
+ </plain>
24
+
25
+ it asks the router to match it to a controller action. If the first matching route is
26
+
27
+ <ruby>
28
+ match "/patients/:id" => "patients#show"
29
+ </ruby>
30
+
31
+ the request is dispatched to the +patients+ controller's +show+ action with <tt>{ :id => "17" }</tt> in +params+.
32
+
33
+ h4. Generating Paths and URLs from Code
34
+
35
+ You can also generate paths and URLs. If your application contains this code:
36
+
37
+ <ruby>
38
+ @patient = Patient.find(17)
39
+ </ruby>
40
+
41
+ <erb>
42
+ <%= link_to "Patient Record", patient_path(@patient) %>
43
+ </erb>
44
+
45
+ The router will generate the path +/patients/17+. This reduces the brittleness of your view and makes your code easier to understand. Note that the id does not need to be specified in the route helper.
46
+
47
+ h3. Resource Routing: the Rails Default
48
+
49
+ Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your +index+, +show+, +new+, +edit+, +create+, +update+ and +destroy+ actions, a resourceful route declares them in a single line of code.
50
+
51
+ h4. Resources on the Web
52
+
53
+ Browsers request pages from Rails by making a request for a URL using a specific HTTP method, such as +GET+, +POST+, +PUT+ and +DELETE+. Each method is a request to perform an operation on the resource. A resource route maps a number of related requests to actions in a single controller.
54
+
55
+ When your Rails application receives an incoming request for
56
+
57
+ <plain>
58
+ DELETE /photos/17
59
+ </plain>
60
+
61
+ it asks the router to map it to a controller action. If the first matching route is
62
+
63
+ <ruby>
64
+ resources :photos
65
+ </ruby>
66
+
67
+ Rails would dispatch that request to the +destroy+ method on the +photos+ controller with <tt>{ :id => "17" }</tt> in +params+.
68
+
69
+ h4. CRUD, Verbs, and Actions
70
+
71
+ In Rails, a resourceful route provides a mapping between HTTP verbs and URLs to controller actions. By convention, each action also maps to particular CRUD operations in a database. A single entry in the routing file, such as
72
+
73
+ <ruby>
74
+ resources :photos
75
+ </ruby>
76
+
77
+ creates seven different routes in your application, all mapping to the +Photos+ controller:
78
+
79
+ |_. HTTP Verb |_.Path |_.action |_.used for |
80
+ |GET |/photos |index |display a list of all photos |
81
+ |GET |/photos/new |new |return an HTML form for creating a new photo |
82
+ |POST |/photos |create |create a new photo |
83
+ |GET |/photos/:id |show |display a specific photo |
84
+ |GET |/photos/:id/edit |edit |return an HTML form for editing a photo |
85
+ |PUT |/photos/:id |update |update a specific photo |
86
+ |DELETE |/photos/:id |destroy |delete a specific photo |
87
+
88
+
89
+ NOTE: Rails routes are matched in the order they are specified, so if you have a +resources :photos+ above a +get 'photos/poll'+ the +show+ action's route for the +resources+ line will be matched before the +get+ line. To fix this, move the +get+ line *above* the +resources+ line so that it is matched first.
90
+
91
+ h4. Paths and URLs
92
+
93
+ Creating a resourceful route will also expose a number of helpers to the controllers in your application. In the case of +resources :photos+:
94
+
95
+ * +photos_path+ returns +/photos+
96
+ * +new_photo_path+ returns +/photos/new+
97
+ * +edit_photo_path(:id)+ returns +/photos/:id/edit+ (for instance, +edit_photo_path(10)+ returns +/photos/10/edit+)
98
+ * +photo_path(:id)+ returns +/photos/:id+ (for instance, +photo_path(10)+ returns +/photos/10+)
99
+
100
+ Each of these helpers has a corresponding +_url+ helper (such as +photos_url+) which returns the same path prefixed with the current host, port and path prefix.
101
+
102
+ NOTE: Because the router uses the HTTP verb and URL to match inbound requests, four URLs map to seven different actions.
103
+
104
+ h4. Defining Multiple Resources at the Same Time
105
+
106
+ If you need to create routes for more than one resource, you can save a bit of typing by defining them all with a single call to +resources+:
107
+
108
+ <ruby>
109
+ resources :photos, :books, :videos
110
+ </ruby>
111
+
112
+ This works exactly the same as
113
+
114
+ <ruby>
115
+ resources :photos
116
+ resources :books
117
+ resources :videos
118
+ </ruby>
119
+
120
+ h4. Singular Resources
121
+
122
+ Sometimes, you have a resource that clients always look up without referencing an ID. For example, you would like +/profile+ to always show the profile of the currently logged in user. In this case, you can use a singular resource to map +/profile+ (rather than +/profile/:id+) to the +show+ action.
123
+
124
+ <ruby>
125
+ match "profile" => "users#show"
126
+ </ruby>
127
+
128
+ This resourceful route
129
+
130
+ <ruby>
131
+ resource :geocoder
132
+ </ruby>
133
+
134
+ creates six different routes in your application, all mapping to the +Geocoders+ controller:
135
+
136
+ |_.HTTP Verb |_.Path |_.action |_.used for |
137
+ |GET |/geocoder/new |new |return an HTML form for creating the geocoder |
138
+ |POST |/geocoder |create |create the new geocoder |
139
+ |GET |/geocoder |show |display the one and only geocoder resource |
140
+ |GET |/geocoder/edit |edit |return an HTML form for editing the geocoder |
141
+ |PUT |/geocoder |update |update the one and only geocoder resource |
142
+ |DELETE |/geocoder |destroy |delete the geocoder resource |
143
+
144
+ NOTE: Because you might want to use the same controller for a singular route (+/account+) and a plural route (+/accounts/45+), singular resources map to plural controllers.
145
+
146
+ A singular resourceful route generates these helpers:
147
+
148
+ * +new_geocoder_path+ returns +/geocoder/new+
149
+ * +edit_geocoder_path+ returns +/geocoder/edit+
150
+ * +geocoder_path+ returns +/geocoder+
151
+
152
+ As with plural resources, the same helpers ending in +_url+ will also include the host, port and path prefix.
153
+
154
+ h4. Controller Namespaces and Routing
155
+
156
+ You may wish to organize groups of controllers under a namespace. Most commonly, you might group a number of administrative controllers under an +Admin::+ namespace. You would place these controllers under the +app/controllers/admin+ directory, and you can group them together in your router:
157
+
158
+ <ruby>
159
+ namespace :admin do
160
+ resources :posts, :comments
161
+ end
162
+ </ruby>
163
+
164
+ This will create a number of routes for each of the +posts+ and +comments+ controller. For +Admin::PostsController+, Rails will create:
165
+
166
+ |_.HTTP Verb |_.Path |_.action |_.named helper |
167
+ |GET |/admin/posts |index | admin_posts_path |
168
+ |GET |/admin/posts/new |new | new_admin_post_path |
169
+ |POST |/admin/posts |create | admin_posts_path |
170
+ |GET |/admin/posts/:id |show | admin_post_path(:id) |
171
+ |GET |/admin/posts/:id/edit |edit | edit_admin_post_path(:id) |
172
+ |PUT |/admin/posts/:id |update | admin_post_path(:id) |
173
+ |DELETE |/admin/posts/:id |destroy | admin_post_path(:id) |
174
+
175
+ If you want to route +/posts+ (without the prefix +/admin+) to +Admin::PostsController+, you could use
176
+
177
+ <ruby>
178
+ scope :module => "admin" do
179
+ resources :posts, :comments
180
+ end
181
+ </ruby>
182
+
183
+ or, for a single case
184
+
185
+ <ruby>
186
+ resources :posts, :module => "admin"
187
+ </ruby>
188
+
189
+ If you want to route +/admin/posts+ to +PostsController+ (without the +Admin::+ module prefix), you could use
190
+
191
+ <ruby>
192
+ scope "/admin" do
193
+ resources :posts, :comments
194
+ end
195
+ </ruby>
196
+
197
+ or, for a single case
198
+
199
+ <ruby>
200
+ resources :posts, :path => "/admin/posts"
201
+ </ruby>
202
+
203
+ In each of these cases, the named routes remain the same as if you did not use +scope+. In the last case, the following paths map to +PostsController+:
204
+
205
+ |_.HTTP Verb |_.Path |_.action |_.named helper |
206
+ |GET |/admin/posts |index | posts_path |
207
+ |GET |/admin/posts/new |new | new_post_path |
208
+ |POST |/admin/posts |create | posts_path |
209
+ |GET |/admin/posts/:id |show | post_path(:id) |
210
+ |GET |/admin/posts/:id/edit|edit | edit_post_path(:id)|
211
+ |PUT |/admin/posts/:id |update | post_path(:id) |
212
+ |DELETE |/admin/posts/:id |destroy | post_path(:id) |
213
+
214
+ h4. Nested Resources
215
+
216
+ It's common to have resources that are logically children of other resources. For example, suppose your application includes these models:
217
+
218
+ <ruby>
219
+ class Magazine < ActiveRecord::Base
220
+ has_many :ads
221
+ end
222
+
223
+ class Ad < ActiveRecord::Base
224
+ belongs_to :magazine
225
+ end
226
+ </ruby>
227
+
228
+ Nested routes allow you to capture this relationship in your routing. In this case, you could include this route declaration:
229
+
230
+ <ruby>
231
+ resources :magazines do
232
+ resources :ads
233
+ end
234
+ </ruby>
235
+
236
+ In addition to the routes for magazines, this declaration will also route ads to an +AdsController+. The ad URLs require a magazine:
237
+
238
+ |_.HTTP Verb |_.Path |_.action |_.used for |
239
+ |GET |/magazines/:magazine_id/ads |index |display a list of all ads for a specific magazine |
240
+ |GET |/magazines/:magazine_id/ads/new |new |return an HTML form for creating a new ad belonging to a specific magazine |
241
+ |POST |/magazines/:magazine_id/ads |create |create a new ad belonging to a specific magazine |
242
+ |GET |/magazines/:magazine_id/ads/:id |show |display a specific ad belonging to a specific magazine |
243
+ |GET |/magazines/:magazine_id/ads/:id/edit |edit |return an HTML form for editing an ad belonging to a specific magazine |
244
+ |PUT |/magazines/:magazine_id/ads/:id |update |update a specific ad belonging to a specific magazine |
245
+ |DELETE |/magazines/:magazine_id/ads/:id |destroy |delete a specific ad belonging to a specific magazine |
246
+
247
+
248
+ This will also create routing helpers such as +magazine_ads_url+ and +edit_magazine_ad_path+. These helpers take an instance of Magazine as the first parameter (+magazine_ads_url(@magazine)+).
249
+
250
+ h5. Limits to Nesting
251
+
252
+ You can nest resources within other nested resources if you like. For example:
253
+
254
+ <ruby>
255
+ resources :publishers do
256
+ resources :magazines do
257
+ resources :photos
258
+ end
259
+ end
260
+ </ruby>
261
+
262
+ Deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize paths such as
263
+
264
+ <pre>
265
+ /publishers/1/magazines/2/photos/3
266
+ </pre>
267
+
268
+ The corresponding route helper would be +publisher_magazine_photo_url+, requiring you to specify objects at all three levels. Indeed, this situation is confusing enough that a popular "article":http://weblog.jamisbuck.org/2007/2/5/nesting-resources by Jamis Buck proposes a rule of thumb for good Rails design:
269
+
270
+ TIP: _Resources should never be nested more than 1 level deep._
271
+
272
+ h4. Creating Paths and URLs From Objects
273
+
274
+ In addition to using the routing helpers, Rails can also create paths and URLs from an array of parameters. For example, suppose you have this set of routes:
275
+
276
+ <ruby>
277
+ resources :magazines do
278
+ resources :ads
279
+ end
280
+ </ruby>
281
+
282
+ When using +magazine_ad_path+, you can pass in instances of +Magazine+ and +Ad+ instead of the numeric IDs.
283
+
284
+ <erb>
285
+ <%= link_to "Ad details", magazine_ad_path(@magazine, @ad) %>
286
+ </erb>
287
+
288
+ You can also use +url_for+ with a set of objects, and Rails will automatically determine which route you want:
289
+
290
+ <erb>
291
+ <%= link_to "Ad details", url_for([@magazine, @ad]) %>
292
+ </erb>
293
+
294
+ In this case, Rails will see that +@magazine+ is a +Magazine+ and +@ad+ is an +Ad+ and will therefore use the +magazine_ad_path+ helper. In helpers like +link_to+, you can specify just the object in place of the full +url_for+ call:
295
+
296
+ <erb>
297
+ <%= link_to "Ad details", [@magazine, @ad] %>
298
+ </erb>
299
+
300
+ If you wanted to link to just a magazine, you could leave out the +Array+:
301
+
302
+ <erb>
303
+ <%= link_to "Magazine details", @magazine %>
304
+ </erb>
305
+
306
+ This allows you to treat instances of your models as URLs, and is a key advantage to using the resourceful style.
307
+
308
+ h4. Adding More RESTful Actions
309
+
310
+ You are not limited to the seven routes that RESTful routing creates by default. If you like, you may add additional routes that apply to the collection or individual members of the collection.
311
+
312
+ h5. Adding Member Routes
313
+
314
+ To add a member route, just add a +member+ block into the resource block:
315
+
316
+ <ruby>
317
+ resources :photos do
318
+ member do
319
+ get 'preview'
320
+ end
321
+ end
322
+ </ruby>
323
+
324
+ This will recognize +/photos/1/preview+ with GET, and route to the +preview+ action of +PhotosController+. It will also create the +preview_photo_url+ and +preview_photo_path+ helpers.
325
+
326
+ Within the block of member routes, each route name specifies the HTTP verb that it will recognize. You can use +get+, +put+, +post+, or +delete+ here. If you don't have multiple +member+ routes, you can also pass +:on+ to a route, eliminating the block:
327
+
328
+ <ruby>
329
+ resources :photos do
330
+ get 'preview', :on => :member
331
+ end
332
+ </ruby>
333
+
334
+ h5. Adding Collection Routes
335
+
336
+ To add a route to the collection:
337
+
338
+ <ruby>
339
+ resources :photos do
340
+ collection do
341
+ get 'search'
342
+ end
343
+ end
344
+ </ruby>
345
+
346
+ This will enable Rails to recognize paths such as +/photos/search+ with GET, and route to the +search+ action of +PhotosController+. It will also create the +search_photos_url+ and +search_photos_path+ route helpers.
347
+
348
+ Just as with member routes, you can pass +:on+ to a route:
349
+
350
+ <ruby>
351
+ resources :photos do
352
+ get 'search', :on => :collection
353
+ end
354
+ </ruby>
355
+
356
+ h5. A Note of Caution
357
+
358
+ If you find yourself adding many extra actions to a resourceful route, it's time to stop and ask yourself whether you're disguising the presence of another resource.
359
+
360
+ h3. Non-Resourceful Routes
361
+
362
+ In addition to resource routing, Rails has powerful support for routing arbitrary URLs to actions. Here, you don't get groups of routes automatically generated by resourceful routing. Instead, you set up each route within your application separately.
363
+
364
+ While you should usually use resourceful routing, there are still many places where the simpler routing is more appropriate. There's no need to try to shoehorn every last piece of your application into a resourceful framework if that's not a good fit.
365
+
366
+ In particular, simple routing makes it very easy to map legacy URLs to new Rails actions.
367
+
368
+ h4. Bound Parameters
369
+
370
+ When you set up a regular route, you supply a series of symbols that Rails maps to parts of an incoming HTTP request. Two of these symbols are special: +:controller+ maps to the name of a controller in your application, and +:action+ maps to the name of an action within that controller. For example, consider one of the default Rails routes:
371
+
372
+ <ruby>
373
+ match ':controller(/:action(/:id))'
374
+ </ruby>
375
+
376
+ If an incoming request of +/photos/show/1+ is processed by this route (because it hasn't matched any previous route in the file), then the result will be to invoke the +show+ action of the +PhotosController+, and to make the final parameter +"1"+ available as +params[:id]+. This route will also route the incoming request of +/photos+ to +PhotosController#index+, since +:action+ and +:id+ are optional parameters, denoted by parentheses.
377
+
378
+ h4. Dynamic Segments
379
+
380
+ You can set up as many dynamic segments within a regular route as you like. Anything other than +:controller+ or +:action+ will be available to the action as part of +params+. If you set up this route:
381
+
382
+ <ruby>
383
+ match ':controller/:action/:id/:user_id'
384
+ </ruby>
385
+
386
+ An incoming path of +/photos/show/1/2+ will be dispatched to the +show+ action of the +PhotosController+. +params[:id]+ will be +"1"+, and +params[:user_id]+ will be +"2"+.
387
+
388
+ NOTE: You can't use +:namespace+ or +:module+ with a +:controller+ path segment. If you need to do this then use a constraint on :controller that matches the namespace you require. e.g:
389
+
390
+ <ruby>
391
+ match ':controller(/:action(/:id))', :controller => /admin\/[^\/]+/
392
+ </ruby>
393
+
394
+ TIP: By default dynamic segments don't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within a dynamic segment add a constraint which overrides this - for example +:id+ => /[^\/]+/ allows anything except a slash.
395
+
396
+ h4. Static Segments
397
+
398
+ You can specify static segments when creating a route:
399
+
400
+ <ruby>
401
+ match ':controller/:action/:id/with_user/:user_id'
402
+ </ruby>
403
+
404
+ This route would respond to paths such as +/photos/show/1/with_user/2+. In this case, +params+ would be <tt>{ :controller => "photos", :action => "show", :id => "1", :user_id => "2" }</tt>.
405
+
406
+ h4. The Query String
407
+
408
+ The +params+ will also include any parameters from the query string. For example, with this route:
409
+
410
+ <ruby>
411
+ match ':controller/:action/:id'
412
+ </ruby>
413
+
414
+ An incoming path of +/photos/show/1?user_id=2+ will be dispatched to the +show+ action of the +Photos+ controller. +params+ will be <tt>{ :controller => "photos", :action => "show", :id => "1", :user_id => "2" }</tt>.
415
+
416
+ h4. Defining Defaults
417
+
418
+ You do not need to explicitly use the +:controller+ and +:action+ symbols within a route. You can supply them as defaults:
419
+
420
+ <ruby>
421
+ match 'photos/:id' => 'photos#show'
422
+ </ruby>
423
+
424
+ With this route, Rails will match an incoming path of +/photos/12+ to the +show+ action of +PhotosController+.
425
+
426
+ You can also define other defaults in a route by supplying a hash for the +:defaults+ option. This even applies to parameters that you do not specify as dynamic segments. For example:
427
+
428
+ <ruby>
429
+ match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }
430
+ </ruby>
431
+
432
+ Rails would match +photos/12+ to the +show+ action of +PhotosController+, and set +params[:format]+ to +"jpg"+.
433
+
434
+ h4. Naming Routes
435
+
436
+ You can specify a name for any route using the +:as+ option.
437
+
438
+ <ruby>
439
+ match 'exit' => 'sessions#destroy', :as => :logout
440
+ </ruby>
441
+
442
+ This will create +logout_path+ and +logout_url+ as named helpers in your application. Calling +logout_path+ will return +/exit+
443
+
444
+ h4. HTTP Verb Constraints
445
+
446
+ You can use the +:via+ option to constrain the request to one or more HTTP methods:
447
+
448
+ <ruby>
449
+ match 'photos/show' => 'photos#show', :via => :get
450
+ </ruby>
451
+
452
+ There is a shorthand version of this as well:
453
+
454
+ <ruby>
455
+ get 'photos/show'
456
+ </ruby>
457
+
458
+ You can also permit more than one verb to a single route:
459
+
460
+ <ruby>
461
+ match 'photos/show' => 'photos#show', :via => [:get, :post]
462
+ </ruby>
463
+
464
+ h4. Segment Constraints
465
+
466
+ You can use the +:constraints+ option to enforce a format for a dynamic segment:
467
+
468
+ <ruby>
469
+ match 'photos/:id' => 'photos#show', :constraints => { :id => /[A-Z]\d{5}/ }
470
+ </ruby>
471
+
472
+ This route would match paths such as +/photos/A12345+. You can more succinctly express the same route this way:
473
+
474
+ <ruby>
475
+ match 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/
476
+ </ruby>
477
+
478
+ +:constraints+ takes regular expressions with the restriction that regexp anchors can't be used. For example, the following route will not work:
479
+
480
+ <ruby>
481
+ match '/:id' => 'posts#show', :constraints => {:id => /^\d/}
482
+ </ruby>
483
+
484
+ However, note that you don't need to use anchors because all routes are anchored at the start.
485
+
486
+ For example, the following routes would allow for +posts+ with +to_param+ values like +1-hello-world+ that always begin with a number and +users+ with +to_param+ values like +david+ that never begin with a number to share the root namespace:
487
+
488
+ <ruby>
489
+ match '/:id' => 'posts#show', :constraints => { :id => /\d.+/ }
490
+ match '/:username' => 'users#show'
491
+ </ruby>
492
+
493
+ h4. Request-Based Constraints
494
+
495
+ You can also constrain a route based on any method on the <a href="action_controller_overview.html#the-request-object">Request</a> object that returns a +String+.
496
+
497
+ You specify a request-based constraint the same way that you specify a segment constraint:
498
+
499
+ <ruby>
500
+ match "photos", :constraints => {:subdomain => "admin"}
501
+ </ruby>
502
+
503
+ You can also specify constraints in a block form:
504
+
505
+ <ruby>
506
+ namespace :admin do
507
+ constraints :subdomain => "admin" do
508
+ resources :photos
509
+ end
510
+ end
511
+ </ruby>
512
+
513
+ h4. Advanced Constraints
514
+
515
+ If you have a more advanced constraint, you can provide an object that responds to +matches?+ that Rails should use. Let's say you wanted to route all users on a blacklist to the +BlacklistController+. You could do:
516
+
517
+ <ruby>
518
+ class BlacklistConstraint
519
+ def initialize
520
+ @ips = Blacklist.retrieve_ips
521
+ end
522
+
523
+ def matches?(request)
524
+ @ips.include?(request.remote_ip)
525
+ end
526
+ end
527
+
528
+ TwitterClone::Application.routes.draw do
529
+ match "*path" => "blacklist#index",
530
+ :constraints => BlacklistConstraint.new
531
+ end
532
+ </ruby>
533
+
534
+ h4. Route Globbing
535
+
536
+ Route globbing is a way to specify that a particular parameter should be matched to all the remaining parts of a route. For example
537
+
538
+ <ruby>
539
+ match 'photos/*other' => 'photos#unknown'
540
+ </ruby>
541
+
542
+ This route would match +photos/12+ or +/photos/long/path/to/12+, setting +params[:other]+ to +"12"+ or +"long/path/to/12"+.
543
+
544
+ Wildcard segments can occur anywhere in a route. For example,
545
+
546
+ <ruby>
547
+ match 'books/*section/:title' => 'books#show'
548
+ </ruby>
549
+
550
+ would match +books/some/section/last-words-a-memoir+ with +params[:section]+ equals +"some/section"+, and +params[:title]+ equals +"last-words-a-memoir"+.
551
+
552
+ Technically a route can have even more than one wildcard segment. The matcher assigns segments to parameters in an intuitive way. For example,
553
+
554
+ <ruby>
555
+ match '*a/foo/*b' => 'test#index'
556
+ </ruby>
557
+
558
+ would match +zoo/woo/foo/bar/baz+ with +params[:a]+ equals +"zoo/woo"+, and +params[:b]+ equals +"bar/baz"+.
559
+
560
+ NOTE: Starting from Rails 3.1, wildcard routes will always match the optional format segment by default. For example if you have this route:
561
+
562
+ <ruby>
563
+ match '*pages' => 'pages#show'
564
+ </ruby>
565
+
566
+ NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to +"foo/bar"+ with the request format of JSON. If you want the old 3.0.x behavior back, you could supply +:format => false+ like this:
567
+
568
+ <ruby>
569
+ match '*pages' => 'pages#show', :format => false
570
+ </ruby>
571
+
572
+ NOTE: If you want to make the format segment mandatory, so it cannot be omitted, you can supply +:format => true+ like this:
573
+
574
+ <ruby>
575
+ match '*pages' => 'pages#show', :format => true
576
+ </ruby>
577
+
578
+ h4. Redirection
579
+
580
+ You can redirect any path to another path using the +redirect+ helper in your router:
581
+
582
+ <ruby>
583
+ match "/stories" => redirect("/posts")
584
+ </ruby>
585
+
586
+ You can also reuse dynamic segments from the match in the path to redirect to:
587
+
588
+ <ruby>
589
+ match "/stories/:name" => redirect("/posts/%{name}")
590
+ </ruby>
591
+
592
+ You can also provide a block to redirect, which receives the params and (optionally) the request object:
593
+
594
+ <ruby>
595
+ match "/stories/:name" => redirect {|params| "/posts/#{params[:name].pluralize}" }
596
+ match "/stories" => redirect {|p, req| "/posts/#{req.subdomain}" }
597
+ </ruby>
598
+
599
+ Please note that this redirection is a 301 "Moved Permanently" redirect. Keep in mind that some web browsers or proxy servers will cache this type of redirect, making the old page inaccessible.
600
+
601
+ In all of these cases, if you don't provide the leading host (+http://www.example.com+), Rails will take those details from the current request.
602
+
603
+ h4. Routing to Rack Applications
604
+
605
+ Instead of a String, like +"posts#index"+, which corresponds to the +index+ action in the +PostsController+, you can specify any <a href="rails_on_rack.html">Rack application</a> as the endpoint for a matcher.
606
+
607
+ <ruby>
608
+ match "/application.js" => Sprockets
609
+ </ruby>
610
+
611
+ As long as +Sprockets+ responds to +call+ and returns a <tt>[status, headers, body]</tt>, the router won't know the difference between the Rack application and an action.
612
+
613
+ NOTE: For the curious, +"posts#index"+ actually expands out to +PostsController.action(:index)+, which returns a valid Rack application.
614
+
615
+ h4. Using +root+
616
+
617
+ You can specify what Rails should route +"/"+ to with the +root+ method:
618
+
619
+ <ruby>
620
+ root :to => 'pages#main'
621
+ </ruby>
622
+
623
+ You should put the +root+ route at the top of the file, because it is the most popular route and should be matched first. You also need to delete the +public/index.html+ file for the root route to take effect.
624
+
625
+ h3. Customizing Resourceful Routes
626
+
627
+ While the default routes and helpers generated by +resources :posts+ will usually serve you well, you may want to customize them in some way. Rails allows you to customize virtually any generic part of the resourceful helpers.
628
+
629
+ h4. Specifying a Controller to Use
630
+
631
+ The +:controller+ option lets you explicitly specify a controller to use for the resource. For example:
632
+
633
+ <ruby>
634
+ resources :photos, :controller => "images"
635
+ </ruby>
636
+
637
+ will recognize incoming paths beginning with +/photos+ but route to the +Images+ controller:
638
+
639
+ |_.HTTP Verb |_.Path |_.action |_.named helper |
640
+ |GET |/photos |index | photos_path |
641
+ |GET |/photos/new |new | new_photo_path |
642
+ |POST |/photos |create | photos_path |
643
+ |GET |/photos/:id |show | photo_path(:id) |
644
+ |GET |/photos/:id/edit |edit | edit_photo_path(:id) |
645
+ |PUT |/photos/:id |update | photo_path(:id) |
646
+ |DELETE |/photos/:id |destroy | photo_path(:id) |
647
+
648
+ NOTE: Use +photos_path+, +new_photo_path+, etc. to generate paths for this resource.
649
+
650
+ h4. Specifying Constraints
651
+
652
+ You can use the +:constraints+ option to specify a required format on the implicit +id+. For example:
653
+
654
+ <ruby>
655
+ resources :photos, :constraints => {:id => /[A-Z][A-Z][0-9]+/}
656
+ </ruby>
657
+
658
+ This declaration constrains the +:id+ parameter to match the supplied regular expression. So, in this case, the router would no longer match +/photos/1+ to this route. Instead, +/photos/RR27+ would match.
659
+
660
+ You can specify a single constraint to apply to a number of routes by using the block form:
661
+
662
+ <ruby>
663
+ constraints(:id => /[A-Z][A-Z][0-9]+/) do
664
+ resources :photos
665
+ resources :accounts
666
+ end
667
+ </ruby>
668
+
669
+ NOTE: Of course, you can use the more advanced constraints available in non-resourceful routes in this context.
670
+
671
+ TIP: By default the +:id+ parameter doesn't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within an +:id+ add a constraint which overrides this - for example +:id+ => /[^\/]+/ allows anything except a slash.
672
+
673
+ h4. Overriding the Named Helpers
674
+
675
+ The +:as+ option lets you override the normal naming for the named route helpers. For example:
676
+
677
+ <ruby>
678
+ resources :photos, :as => "images"
679
+ </ruby>
680
+
681
+ will recognize incoming paths beginning with +/photos+ and route the requests to +PhotosController+, but use the value of the :as option to name the helpers.
682
+
683
+ |_.HTTP verb|_.Path |_.action |_.named helper |
684
+ |GET |/photos |index | images_path |
685
+ |GET |/photos/new |new | new_image_path |
686
+ |POST |/photos |create | images_path |
687
+ |GET |/photos/:id |show | image_path(:id) |
688
+ |GET |/photos/:id/edit |edit | edit_image_path(:id) |
689
+ |PUT |/photos/:id |update | image_path(:id) |
690
+ |DELETE |/photos/:id |destroy | image_path(:id) |
691
+
692
+ h4. Overriding the +new+ and +edit+ Segments
693
+
694
+ The +:path_names+ option lets you override the automatically-generated "new" and "edit" segments in paths:
695
+
696
+ <ruby>
697
+ resources :photos, :path_names => { :new => 'make', :edit => 'change' }
698
+ </ruby>
699
+
700
+ This would cause the routing to recognize paths such as
701
+
702
+ <plain>
703
+ /photos/make
704
+ /photos/1/change
705
+ </plain>
706
+
707
+ NOTE: The actual action names aren't changed by this option. The two paths shown would still route to the +new+ and +edit+ actions.
708
+
709
+ TIP: If you find yourself wanting to change this option uniformly for all of your routes, you can use a scope.
710
+
711
+ <ruby>
712
+ scope :path_names => { :new => "make" } do
713
+ # rest of your routes
714
+ end
715
+ </ruby>
716
+
717
+ h4. Prefixing the Named Route Helpers
718
+
719
+ You can use the +:as+ option to prefix the named route helpers that Rails generates for a route. Use this option to prevent name collisions between routes using a path scope.
720
+
721
+ <ruby>
722
+ scope "admin" do
723
+ resources :photos, :as => "admin_photos"
724
+ end
725
+
726
+ resources :photos
727
+ </ruby>
728
+
729
+ This will provide route helpers such as +admin_photos_path+, +new_admin_photo_path+ etc.
730
+
731
+ To prefix a group of route helpers, use +:as+ with +scope+:
732
+
733
+ <ruby>
734
+ scope "admin", :as => "admin" do
735
+ resources :photos, :accounts
736
+ end
737
+
738
+ resources :photos, :accounts
739
+ </ruby>
740
+
741
+ This will generate routes such as +admin_photos_path+ and +admin_accounts_path+ which map to +/admin/photos+ and +/admin/accounts+ respectively.
742
+
743
+ NOTE: The +namespace+ scope will automatically add +:as+ as well as +:module+ and +:path+ prefixes.
744
+
745
+ You can prefix routes with a named parameter also:
746
+
747
+ <ruby>
748
+ scope ":username" do
749
+ resources :posts
750
+ end
751
+ </ruby>
752
+
753
+ This will provide you with URLs such as +/bob/posts/1+ and will allow you to reference the +username+ part of the path as +params[:username]+ in controllers, helpers and views.
754
+
755
+ h4. Restricting the Routes Created
756
+
757
+ By default, Rails creates routes for the seven default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the +:only+ and +:except+ options to fine-tune this behavior. The +:only+ option tells Rails to create only the specified routes:
758
+
759
+ <ruby>
760
+ resources :photos, :only => [:index, :show]
761
+ </ruby>
762
+
763
+ Now, a +GET+ request to +/photos+ would succeed, but a +POST+ request to +/photos+ (which would ordinarily be routed to the +create+ action) will fail.
764
+
765
+ The +:except+ option specifies a route or list of routes that Rails should _not_ create:
766
+
767
+ <ruby>
768
+ resources :photos, :except => :destroy
769
+ </ruby>
770
+
771
+ In this case, Rails will create all of the normal routes except the route for +destroy+ (a +DELETE+ request to +/photos/:id+).
772
+
773
+ TIP: If your application has many RESTful routes, using +:only+ and +:except+ to generate only the routes that you actually need can cut down on memory use and speed up the routing process.
774
+
775
+ h4. Translated Paths
776
+
777
+ Using +scope+, we can alter path names generated by resources:
778
+
779
+ <ruby>
780
+ scope(:path_names => { :new => "neu", :edit => "bearbeiten" }) do
781
+ resources :categories, :path => "kategorien"
782
+ end
783
+ </ruby>
784
+
785
+ Rails now creates routes to the +CategoriesController+.
786
+
787
+ |_.HTTP verb|_.Path |_.action |_.named helper |
788
+ |GET |/kategorien |index | categories_path |
789
+ |GET |/kategorien/neu |new | new_category_path |
790
+ |POST |/kategorien |create | categories_path |
791
+ |GET |/kategorien/:id |show | category_path(:id) |
792
+ |GET |/kategorien/:id/bearbeiten |edit | edit_category_path(:id) |
793
+ |PUT |/kategorien/:id |update | category_path(:id) |
794
+ |DELETE |/kategorien/:id |destroy | category_path(:id) |
795
+
796
+ h4. Overriding the Singular Form
797
+
798
+ If you want to define the singular form of a resource, you should add additional rules to the +Inflector+.
799
+
800
+ <ruby>
801
+ ActiveSupport::Inflector.inflections do |inflect|
802
+ inflect.irregular 'tooth', 'teeth'
803
+ end
804
+ </ruby>
805
+
806
+ h4(#nested-names). Using +:as+ in Nested Resources
807
+
808
+ The +:as+ option overrides the automatically-generated name for the resource in nested route helpers. For example,
809
+
810
+ <ruby>
811
+ resources :magazines do
812
+ resources :ads, :as => 'periodical_ads'
813
+ end
814
+ </ruby>
815
+
816
+ This will create routing helpers such as +magazine_periodical_ads_url+ and +edit_magazine_periodical_ad_path+.
817
+
818
+ h3. Inspecting and Testing Routes
819
+
820
+ Rails offers facilities for inspecting and testing your routes.
821
+
822
+ h4. Seeing Existing Routes with +rake+
823
+
824
+ If you want a complete list of all of the available routes in your application, run +rake routes+ command. This will print all of your routes, in the same order that they appear in +routes.rb+. For each route, you'll see:
825
+
826
+ * The route name (if any)
827
+ * The HTTP verb used (if the route doesn't respond to all verbs)
828
+ * The URL pattern to match
829
+ * The routing parameters for the route
830
+
831
+ For example, here's a small section of the +rake routes+ output for a RESTful route:
832
+
833
+ <pre>
834
+ users GET /users(.:format) users#index
835
+ POST /users(.:format) users#create
836
+ new_user GET /users/new(.:format) users#new
837
+ edit_user GET /users/:id/edit(.:format) users#edit
838
+ </pre>
839
+
840
+ You may restrict the listing to the routes that map to a particular controller setting the +CONTROLLER+ environment variable:
841
+
842
+ <shell>
843
+ $ CONTROLLER=users rake routes
844
+ </shell>
845
+
846
+ TIP: You'll find that the output from +rake routes+ is much more readable if you widen your terminal window until the output lines don't wrap.
847
+
848
+ h4. Testing Routes
849
+
850
+ Routes should be included in your testing strategy (just like the rest of your application). Rails offers three "built-in assertions":http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html designed to make testing routes simpler:
851
+
852
+ * +assert_generates+
853
+ * +assert_recognizes+
854
+ * +assert_routing+
855
+
856
+ h5. The +assert_generates+ Assertion
857
+
858
+ +assert_generates+ asserts that a particular set of options generate a particular path and can be used with default routes or custom routes.
859
+
860
+ <ruby>
861
+ assert_generates "/photos/1", { :controller => "photos", :action => "show", :id => "1" }
862
+ assert_generates "/about", :controller => "pages", :action => "about"
863
+ </ruby>
864
+
865
+ h5. The +assert_recognizes+ Assertion
866
+
867
+ +assert_recognizes+ is the inverse of +assert_generates+. It asserts that a given path is recognized and routes it to a particular spot in your application.
868
+
869
+ <ruby>
870
+ assert_recognizes({ :controller => "photos", :action => "show", :id => "1" }, "/photos/1")
871
+ </ruby>
872
+
873
+ You can supply a +:method+ argument to specify the HTTP verb:
874
+
875
+ <ruby>
876
+ assert_recognizes({ :controller => "photos", :action => "create" }, { :path => "photos", :method => :post })
877
+ </ruby>
878
+
879
+ h5. The +assert_routing+ Assertion
880
+
881
+ The +assert_routing+ assertion checks the route both ways: it tests that the path generates the options, and that the options generate the path. Thus, it combines the functions of +assert_generates+ and +assert_recognizes+.
882
+
883
+ <ruby>
884
+ assert_routing({ :path => "photos", :method => :post }, { :controller => "photos", :action => "create" })
885
+ </ruby>