rails 3.2.22.5 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (281) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +77 -0
  3. data/guides/CHANGELOG.md +9 -0
  4. data/guides/Rakefile +77 -0
  5. data/guides/assets/images/belongs_to.png +0 -0
  6. data/guides/assets/images/book_icon.gif +0 -0
  7. data/guides/assets/images/bullet.gif +0 -0
  8. data/guides/assets/images/challenge.png +0 -0
  9. data/guides/assets/images/chapters_icon.gif +0 -0
  10. data/guides/assets/images/check_bullet.gif +0 -0
  11. data/guides/assets/images/credits_pic_blank.gif +0 -0
  12. data/guides/assets/images/csrf.png +0 -0
  13. data/guides/assets/images/edge_badge.png +0 -0
  14. data/guides/assets/images/favicon.ico +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/getting_started/confirm_dialog.png +0 -0
  19. data/guides/assets/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  20. data/guides/assets/images/getting_started/form_with_errors.png +0 -0
  21. data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
  22. data/guides/assets/images/getting_started/new_post.png +0 -0
  23. data/guides/assets/images/getting_started/post_with_comments.png +0 -0
  24. data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
  25. data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
  26. data/guides/assets/images/getting_started/show_action_for_posts.png +0 -0
  27. data/guides/assets/images/getting_started/template_is_missing_posts_new.png +0 -0
  28. data/guides/assets/images/getting_started/undefined_method_post_path.png +0 -0
  29. data/guides/assets/images/getting_started/unknown_action_create_for_posts.png +0 -0
  30. data/guides/assets/images/getting_started/unknown_action_new_for_posts.png +0 -0
  31. data/guides/assets/images/grey_bullet.gif +0 -0
  32. data/guides/assets/images/habtm.png +0 -0
  33. data/guides/assets/images/has_many.png +0 -0
  34. data/guides/assets/images/has_many_through.png +0 -0
  35. data/guides/assets/images/has_one.png +0 -0
  36. data/guides/assets/images/has_one_through.png +0 -0
  37. data/guides/assets/images/header_backdrop.png +0 -0
  38. data/guides/assets/images/header_tile.gif +0 -0
  39. data/guides/assets/images/i18n/demo_html_safe.png +0 -0
  40. data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
  41. data/guides/assets/images/i18n/demo_translated_en.png +0 -0
  42. data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
  43. data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
  44. data/guides/assets/images/i18n/demo_untranslated.png +0 -0
  45. data/guides/assets/images/icons/README +5 -0
  46. data/guides/assets/images/icons/callouts/1.png +0 -0
  47. data/guides/assets/images/icons/callouts/10.png +0 -0
  48. data/guides/assets/images/icons/callouts/11.png +0 -0
  49. data/guides/assets/images/icons/callouts/12.png +0 -0
  50. data/guides/assets/images/icons/callouts/13.png +0 -0
  51. data/guides/assets/images/icons/callouts/14.png +0 -0
  52. data/guides/assets/images/icons/callouts/15.png +0 -0
  53. data/guides/assets/images/icons/callouts/2.png +0 -0
  54. data/guides/assets/images/icons/callouts/3.png +0 -0
  55. data/guides/assets/images/icons/callouts/4.png +0 -0
  56. data/guides/assets/images/icons/callouts/5.png +0 -0
  57. data/guides/assets/images/icons/callouts/6.png +0 -0
  58. data/guides/assets/images/icons/callouts/7.png +0 -0
  59. data/guides/assets/images/icons/callouts/8.png +0 -0
  60. data/guides/assets/images/icons/callouts/9.png +0 -0
  61. data/guides/assets/images/icons/caution.png +0 -0
  62. data/guides/assets/images/icons/example.png +0 -0
  63. data/guides/assets/images/icons/home.png +0 -0
  64. data/guides/assets/images/icons/important.png +0 -0
  65. data/guides/assets/images/icons/next.png +0 -0
  66. data/guides/assets/images/icons/note.png +0 -0
  67. data/guides/assets/images/icons/prev.png +0 -0
  68. data/guides/assets/images/icons/tip.png +0 -0
  69. data/guides/assets/images/icons/up.png +0 -0
  70. data/guides/assets/images/icons/warning.png +0 -0
  71. data/guides/assets/images/jaimeiniesta.jpg +0 -0
  72. data/guides/assets/images/nav_arrow.gif +0 -0
  73. data/guides/assets/images/oscardelben.jpg +0 -0
  74. data/guides/assets/images/polymorphic.png +0 -0
  75. data/guides/assets/images/radar.png +0 -0
  76. data/guides/assets/images/rails4_features.png +0 -0
  77. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  78. data/guides/assets/images/rails_guides_logo.gif +0 -0
  79. data/guides/assets/images/rails_logo_remix.gif +0 -0
  80. data/guides/assets/images/rails_welcome.png +0 -0
  81. data/guides/assets/images/session_fixation.png +0 -0
  82. data/guides/assets/images/tab_grey.gif +0 -0
  83. data/guides/assets/images/tab_info.gif +0 -0
  84. data/guides/assets/images/tab_note.gif +0 -0
  85. data/guides/assets/images/tab_red.gif +0 -0
  86. data/guides/assets/images/tab_yellow.gif +0 -0
  87. data/guides/assets/images/tab_yellow.png +0 -0
  88. data/guides/assets/images/vijaydev.jpg +0 -0
  89. data/guides/assets/javascripts/guides.js +57 -0
  90. data/guides/assets/javascripts/jquery.min.js +4 -0
  91. data/guides/assets/javascripts/responsive-tables.js +43 -0
  92. data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
  93. data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
  94. data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
  95. data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
  96. data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
  97. data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
  98. data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
  99. data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
  100. data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
  101. data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
  102. data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
  103. data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
  104. data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
  105. data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
  106. data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
  107. data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
  108. data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
  109. data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
  110. data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
  111. data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
  112. data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
  113. data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
  114. data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
  115. data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
  116. data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
  117. data/guides/assets/javascripts/syntaxhighlighter/shCore.js +17 -0
  118. data/guides/assets/stylesheets/fixes.css +16 -0
  119. data/guides/assets/stylesheets/kindle.css +11 -0
  120. data/guides/assets/stylesheets/main.css +709 -0
  121. data/guides/assets/stylesheets/print.css +52 -0
  122. data/guides/assets/stylesheets/reset.css +43 -0
  123. data/guides/assets/stylesheets/responsive-tables.css +50 -0
  124. data/guides/assets/stylesheets/style.css +13 -0
  125. data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +226 -0
  126. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
  127. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
  128. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
  129. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
  130. data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
  131. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
  132. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
  133. data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
  134. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
  135. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
  136. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
  137. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
  138. data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
  139. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
  140. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
  141. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
  142. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
  143. data/guides/code/getting_started/Gemfile +38 -0
  144. data/guides/code/getting_started/Gemfile.lock +150 -0
  145. data/guides/code/getting_started/README.rdoc +28 -0
  146. data/guides/code/getting_started/Rakefile +6 -0
  147. data/guides/code/getting_started/app/assets/images/rails.png +0 -0
  148. data/guides/code/getting_started/app/assets/javascripts/application.js +16 -0
  149. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
  150. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
  151. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +3 -0
  152. data/guides/code/getting_started/app/assets/stylesheets/application.css +13 -0
  153. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
  154. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
  155. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +3 -0
  156. data/guides/code/getting_started/app/controllers/application_controller.rb +5 -0
  157. data/guides/code/getting_started/app/controllers/comments_controller.rb +17 -0
  158. data/guides/code/getting_started/app/controllers/posts_controller.rb +47 -0
  159. data/guides/code/getting_started/app/controllers/welcome_controller.rb +4 -0
  160. data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
  161. data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
  162. data/guides/code/getting_started/app/helpers/posts_helper.rb +2 -0
  163. data/guides/code/getting_started/app/helpers/welcome_helper.rb +2 -0
  164. data/guides/code/getting_started/app/models/comment.rb +3 -0
  165. data/guides/code/getting_started/app/models/post.rb +7 -0
  166. data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
  167. data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
  168. data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
  169. data/guides/code/getting_started/app/views/posts/_form.html.erb +27 -0
  170. data/guides/code/getting_started/app/views/posts/edit.html.erb +5 -0
  171. data/guides/code/getting_started/app/views/posts/index.html.erb +21 -0
  172. data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
  173. data/guides/code/getting_started/app/views/posts/show.html.erb +18 -0
  174. data/guides/code/getting_started/app/views/welcome/index.html.erb +3 -0
  175. data/guides/code/getting_started/bin/bundle +4 -0
  176. data/guides/code/getting_started/bin/rails +4 -0
  177. data/guides/code/getting_started/bin/rake +4 -0
  178. data/guides/code/getting_started/config.ru +4 -0
  179. data/guides/code/getting_started/config/application.rb +17 -0
  180. data/guides/code/getting_started/config/boot.rb +4 -0
  181. data/guides/code/getting_started/config/database.yml +25 -0
  182. data/guides/code/getting_started/config/environment.rb +5 -0
  183. data/guides/code/getting_started/config/environments/development.rb +30 -0
  184. data/guides/code/getting_started/config/environments/production.rb +80 -0
  185. data/guides/code/getting_started/config/environments/test.rb +36 -0
  186. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
  187. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +4 -0
  188. data/guides/code/getting_started/config/initializers/inflections.rb +16 -0
  189. data/guides/code/getting_started/config/initializers/locale.rb +9 -0
  190. data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
  191. data/guides/code/getting_started/config/initializers/secret_token.rb +12 -0
  192. data/guides/code/getting_started/config/initializers/session_store.rb +3 -0
  193. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
  194. data/guides/code/getting_started/config/locales/en.yml +23 -0
  195. data/guides/code/getting_started/config/routes.rb +7 -0
  196. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +10 -0
  197. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +11 -0
  198. data/guides/code/getting_started/db/schema.rb +33 -0
  199. data/guides/code/getting_started/db/seeds.rb +7 -0
  200. data/guides/code/getting_started/public/404.html +27 -0
  201. data/guides/code/getting_started/public/422.html +26 -0
  202. data/guides/code/getting_started/public/500.html +26 -0
  203. data/guides/code/getting_started/public/favicon.ico +0 -0
  204. data/guides/code/getting_started/public/robots.txt +5 -0
  205. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +7 -0
  206. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +7 -0
  207. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +9 -0
  208. data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
  209. data/guides/code/getting_started/test/fixtures/posts.yml +9 -0
  210. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +4 -0
  211. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +4 -0
  212. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +4 -0
  213. data/guides/code/getting_started/test/models/comment_test.rb +7 -0
  214. data/guides/code/getting_started/test/models/post_test.rb +7 -0
  215. data/guides/code/getting_started/test/test_helper.rb +15 -0
  216. data/guides/rails_guides.rb +44 -0
  217. data/guides/rails_guides/generator.rb +248 -0
  218. data/guides/rails_guides/helpers.rb +51 -0
  219. data/guides/rails_guides/indexer.rb +68 -0
  220. data/guides/rails_guides/kindle.rb +119 -0
  221. data/guides/rails_guides/levenshtein.rb +31 -0
  222. data/guides/rails_guides/markdown.rb +163 -0
  223. data/guides/rails_guides/markdown/renderer.rb +82 -0
  224. data/guides/source/2_2_release_notes.md +435 -0
  225. data/guides/source/2_3_release_notes.md +621 -0
  226. data/guides/source/3_0_release_notes.md +614 -0
  227. data/guides/source/3_1_release_notes.md +556 -0
  228. data/guides/source/3_2_release_notes.md +565 -0
  229. data/guides/source/4_0_release_notes.md +228 -0
  230. data/guides/source/_license.html.erb +2 -0
  231. data/guides/source/_welcome.html.erb +19 -0
  232. data/guides/source/action_controller_overview.md +872 -0
  233. data/guides/source/action_mailer_basics.md +599 -0
  234. data/guides/source/action_view_overview.md +1565 -0
  235. data/guides/source/active_model_basics.md +200 -0
  236. data/guides/source/active_record_basics.md +370 -0
  237. data/guides/source/active_record_callbacks.md +358 -0
  238. data/guides/source/active_record_querying.md +1621 -0
  239. data/guides/source/active_record_validations.md +1128 -0
  240. data/guides/source/active_support_core_extensions.md +3791 -0
  241. data/guides/source/active_support_instrumentation.md +487 -0
  242. data/guides/source/api_documentation_guidelines.md +209 -0
  243. data/guides/source/asset_pipeline.md +832 -0
  244. data/guides/source/association_basics.md +2129 -0
  245. data/guides/source/caching_with_rails.md +350 -0
  246. data/guides/source/command_line.md +594 -0
  247. data/guides/source/configuring.md +736 -0
  248. data/guides/source/contributing_to_ruby_on_rails.md +455 -0
  249. data/guides/source/credits.html.erb +76 -0
  250. data/guides/source/debugging_rails_applications.md +675 -0
  251. data/guides/source/development_dependencies_install.md +195 -0
  252. data/guides/source/documents.yaml +179 -0
  253. data/guides/source/engines.md +961 -0
  254. data/guides/source/form_helpers.md +955 -0
  255. data/guides/source/generators.md +644 -0
  256. data/guides/source/getting_started.md +1775 -0
  257. data/guides/source/i18n.md +983 -0
  258. data/guides/source/index.html.erb +27 -0
  259. data/guides/source/initialization.md +562 -0
  260. data/guides/source/kindle/KINDLE.md +26 -0
  261. data/guides/source/kindle/copyright.html.erb +1 -0
  262. data/guides/source/kindle/layout.html.erb +27 -0
  263. data/guides/source/kindle/rails_guides.opf.erb +52 -0
  264. data/guides/source/kindle/toc.html.erb +24 -0
  265. data/guides/source/kindle/toc.ncx.erb +64 -0
  266. data/guides/source/kindle/welcome.html.erb +5 -0
  267. data/guides/source/layout.html.erb +148 -0
  268. data/guides/source/layouts_and_rendering.md +1132 -0
  269. data/guides/source/migrations.md +1059 -0
  270. data/guides/source/nested_model_forms.md +225 -0
  271. data/guides/source/plugins.md +435 -0
  272. data/guides/source/rails_application_templates.md +229 -0
  273. data/guides/source/rails_on_rack.md +342 -0
  274. data/guides/source/routing.md +1088 -0
  275. data/guides/source/ruby_on_rails_guides_guidelines.md +124 -0
  276. data/guides/source/security.md +973 -0
  277. data/guides/source/testing.md +981 -0
  278. data/guides/source/upgrading_ruby_on_rails.md +286 -0
  279. data/guides/source/working_with_javascript_in_rails.md +396 -0
  280. data/guides/w3c_validator.rb +95 -0
  281. metadata +315 -31
@@ -0,0 +1,76 @@
1
+ <% content_for :page_title do %>
2
+ Ruby on Rails Guides: Credits
3
+ <% end %>
4
+
5
+ <% content_for :header_section do %>
6
+ <h2>Credits</h2>
7
+
8
+ <p>We'd like to thank the following people for their tireless contributions to this project.</p>
9
+
10
+ <% end %>
11
+
12
+ <h3 class="section">Rails Guides Reviewers</h3>
13
+
14
+ <%= author('Vijay Dev', 'vijaydev', 'vijaydev.jpg') do %>
15
+ Vijayakumar, found as Vijay Dev on the web, is a web applications developer and an open source enthusiast who lives in Chennai, India. He started using Rails in 2009 and began actively contributing to Rails documentation in late 2010. He <a href="https://twitter.com/vijay_dev">tweets</a> a lot and also <a href="http://vijaydev.wordpress.com">blogs</a>.
16
+ <% end %>
17
+
18
+ <%= author('Xavier Noria', 'fxn', 'fxn.png') do %>
19
+ Xavier Noria has been into Ruby on Rails since 2005. He is a Rails core team member and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Xavier is currently an independent Ruby on Rails consultant. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as &quot;fxn&quot;.
20
+ <% end %>
21
+
22
+ <h3 class="section">Rails Guides Designers</h3>
23
+
24
+ <%= author('Jason Zimdars', 'jz') do %>
25
+ Jason Zimdars is an experienced creative director and web designer who has lead UI and UX design for numerous websites and web applications. You can see more of his design and writing at <a href="http://www.thinkcage.com/">Thinkcage.com</a> or follow him on <a href="http://twitter.com/JZ">Twitter</a>.
26
+ <% end %>
27
+
28
+ <h3 class="section">Rails Guides Authors</h3>
29
+
30
+ <%= author('Ryan Bigg', 'radar', 'radar.png') do %>
31
+ Ryan Bigg works as a consultant at <a href="http://rubyx.com">RubyX</a> and has been working with Rails since 2006. He's co-authoring a book called <a href="http://manning.com/katz">Rails 3 in Action</a> and he's written many gems which can be seen on <a href="https://github.com/radar">his GitHub page</a> and he also tweets prolifically as <a href="http://twitter.com/ryanbigg">@ryanbigg</a>.
32
+ <% end %>
33
+
34
+ <%= author('Oscar Del Ben', 'oscardelben', 'oscardelben.jpg') do %>
35
+ Oscar Del Ben is a software engineer at <a href="http://www.wildfireapp.com/">Wildfire</a>. He's a regular open source contributor (<a href="https://github.com/oscardelben">Github account</a>) and tweets regularly at <a href="https://twitter.com/oscardelben">@oscardelben</a>.
36
+ <% end %>
37
+
38
+ <%= author('Frederick Cheung', 'fcheung') do %>
39
+ Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006. He is based in Cambridge (UK) and when not consuming fine ales he blogs at <a href="http://www.spacevatican.org">spacevatican.org</a>.
40
+ <% end %>
41
+
42
+ <%= author('Tore Darell', 'toretore') do %>
43
+ Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails and unobtrusive JavaScript. His home on the internet is his blog <a href="http://tore.darell.no">Sneaky Abstractions</a>.
44
+ <% end %>
45
+
46
+ <%= author('Jeff Dean', 'zilkey') do %>
47
+ Jeff Dean is a software engineer with <a href="http://pivotallabs.com">Pivotal Labs</a>.
48
+ <% end %>
49
+
50
+ <%= author('Mike Gunderloy', 'mgunderloy') do %>
51
+ Mike Gunderloy is a consultant with <a href="http://www.actionrails.com">ActionRails</a>. He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at <a href="http://afreshcup.com">A Fresh Cup</a> and he <a href="http://twitter.com/MikeG1">twitters</a> too much.
52
+ <% end %>
53
+
54
+ <%= author('Mikel Lindsaar', 'raasdnil') do %>
55
+ Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a href="https://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
56
+ <% end %>
57
+
58
+ <%= author('Cássio Marques', 'cmarques') do %>
59
+ Cássio Marques is a Brazilian software developer working with different programming languages such as Ruby, JavaScript, CPP and Java, as an independent consultant. He blogs at <a href="http://cassiomarques.wordpress.com">/* CODIFICANDO */</a>, which is mainly written in Portuguese, but will soon get a new section for posts with English translation.
60
+ <% end %>
61
+
62
+ <%= author('James Miller', 'bensie') do %>
63
+ James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA. You can find James on GitHub, Gmail, Twitter, and Freenode as &quot;bensie&quot;.
64
+ <% end %>
65
+
66
+ <%= author('Pratik Naik', 'lifo') do %>
67
+ Pratik Naik is a Ruby on Rails developer at <a href="http://www.37signals.com">37signals</a> and also a member of the <a href="http://rubyonrails.org/core">Rails core team</a>. He maintains a blog at <a href="http://m.onkey.org">has_many :bugs, :through =&gt; :rails</a> and has a semi-active <a href="http://twitter.com/lifo">twitter account</a>.
68
+ <% end %>
69
+
70
+ <%= author('Emilio Tagua', 'miloops') do %>
71
+ Emilio Tagua &mdash;a.k.a. miloops&mdash; is an Argentinian entrepreneur, developer, open source contributor and Rails evangelist. Cofounder of <a href="http://eventioz.com">Eventioz</a>. He has been using Rails since 2006 and contributing since early 2008. Can be found at gmail, twitter, freenode, everywhere as &quot;miloops&quot;.
72
+ <% end %>
73
+
74
+ <%= author('Heiko Webers', 'hawe') do %>
75
+ Heiko Webers is the founder of <a href="http://www.bauland42.de">bauland42</a>, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the <a href="http://www.rorsecurity.info">Ruby on Rails Security Project</a>. After 10 years of desktop application development, Heiko has rarely looked back.
76
+ <% end %>
@@ -0,0 +1,675 @@
1
+ Debugging Rails Applications
2
+ ============================
3
+
4
+ This guide introduces techniques for debugging Ruby on Rails applications.
5
+
6
+ After reading this guide, you will know:
7
+
8
+ * The purpose of debugging.
9
+ * How to track down problems and issues in your application that your tests aren't identifying.
10
+ * The different ways of debugging.
11
+ * How to analyze the stack trace.
12
+
13
+ --------------------------------------------------------------------------------
14
+
15
+ View Helpers for Debugging
16
+ --------------------------
17
+
18
+ One common task is to inspect the contents of a variable. In Rails, you can do this with three methods:
19
+
20
+ * `debug`
21
+ * `to_yaml`
22
+ * `inspect`
23
+
24
+ ### `debug`
25
+
26
+ The `debug` helper will return a \<pre>-tag that renders the object using the YAML format. This will generate human-readable data from any object. For example, if you have this code in a view:
27
+
28
+ ```html+erb
29
+ <%= debug @post %>
30
+ <p>
31
+ <b>Title:</b>
32
+ <%= @post.title %>
33
+ </p>
34
+ ```
35
+
36
+ You'll see something like this:
37
+
38
+ ```yaml
39
+ --- !ruby/object:Post
40
+ attributes:
41
+ updated_at: 2008-09-05 22:55:47
42
+ body: It's a very helpful guide for debugging your Rails app.
43
+ title: Rails debugging guide
44
+ published: t
45
+ id: "1"
46
+ created_at: 2008-09-05 22:55:47
47
+ attributes_cache: {}
48
+
49
+
50
+ Title: Rails debugging guide
51
+ ```
52
+
53
+ ### `to_yaml`
54
+
55
+ Displaying an instance variable, or any other object or method, in YAML format can be achieved this way:
56
+
57
+ ```html+erb
58
+ <%= simple_format @post.to_yaml %>
59
+ <p>
60
+ <b>Title:</b>
61
+ <%= @post.title %>
62
+ </p>
63
+ ```
64
+
65
+ The `to_yaml` method converts the method to YAML format leaving it more readable, and then the `simple_format` helper is used to render each line as in the console. This is how `debug` method does its magic.
66
+
67
+ As a result of this, you will have something like this in your view:
68
+
69
+ ```yaml
70
+ --- !ruby/object:Post
71
+ attributes:
72
+ updated_at: 2008-09-05 22:55:47
73
+ body: It's a very helpful guide for debugging your Rails app.
74
+ title: Rails debugging guide
75
+ published: t
76
+ id: "1"
77
+ created_at: 2008-09-05 22:55:47
78
+ attributes_cache: {}
79
+
80
+ Title: Rails debugging guide
81
+ ```
82
+
83
+ ### `inspect`
84
+
85
+ Another useful method for displaying object values is `inspect`, especially when working with arrays or hashes. This will print the object value as a string. For example:
86
+
87
+ ```html+erb
88
+ <%= [1, 2, 3, 4, 5].inspect %>
89
+ <p>
90
+ <b>Title:</b>
91
+ <%= @post.title %>
92
+ </p>
93
+ ```
94
+
95
+ Will be rendered as follows:
96
+
97
+ ```
98
+ [1, 2, 3, 4, 5]
99
+
100
+ Title: Rails debugging guide
101
+ ```
102
+
103
+ The Logger
104
+ ----------
105
+
106
+ It can also be useful to save information to log files at runtime. Rails maintains a separate log file for each runtime environment.
107
+
108
+ ### What is the Logger?
109
+
110
+ Rails makes use of the `ActiveSupport::Logger` class to write log information. You can also substitute another logger such as `Log4r` if you wish.
111
+
112
+ You can specify an alternative logger in your `environment.rb` or any environment file:
113
+
114
+ ```ruby
115
+ Rails.logger = Logger.new(STDOUT)
116
+ Rails.logger = Log4r::Logger.new("Application Log")
117
+ ```
118
+
119
+ Or in the `Initializer` section, add _any_ of the following
120
+
121
+ ```ruby
122
+ config.logger = Logger.new(STDOUT)
123
+ config.logger = Log4r::Logger.new("Application Log")
124
+ ```
125
+
126
+ TIP: By default, each log is created under `Rails.root/log/` and the log file name is `environment_name.log`.
127
+
128
+ ### Log Levels
129
+
130
+ When something is logged it's printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the `Rails.logger.level` method.
131
+
132
+ The available log levels are: `:debug`, `:info`, `:warn`, `:error`, `:fatal`, and `:unknown`, corresponding to the log level numbers from 0 up to 5 respectively. To change the default log level, use
133
+
134
+ ```ruby
135
+ config.log_level = :warn # In any environment initializer, or
136
+ Rails.logger.level = 0 # at any time
137
+ ```
138
+
139
+ This is useful when you want to log under development or staging, but you don't want to flood your production log with unnecessary information.
140
+
141
+ TIP: The default Rails log level is `info` in production mode and `debug` in development and test mode.
142
+
143
+ ### Sending Messages
144
+
145
+ To write in the current log use the `logger.(debug|info|warn|error|fatal)` method from within a controller, model or mailer:
146
+
147
+ ```ruby
148
+ logger.debug "Person attributes hash: #{@person.attributes.inspect}"
149
+ logger.info "Processing the request..."
150
+ logger.fatal "Terminating application, raised unrecoverable error!!!"
151
+ ```
152
+
153
+ Here's an example of a method instrumented with extra logging:
154
+
155
+ ```ruby
156
+ class PostsController < ApplicationController
157
+ # ...
158
+
159
+ def create
160
+ @post = Post.new(params[:post])
161
+ logger.debug "New post: #{@post.attributes.inspect}"
162
+ logger.debug "Post should be valid: #{@post.valid?}"
163
+
164
+ if @post.save
165
+ flash[:notice] = 'Post was successfully created.'
166
+ logger.debug "The post was saved and now the user is going to be redirected..."
167
+ redirect_to(@post)
168
+ else
169
+ render action: "new"
170
+ end
171
+ end
172
+
173
+ # ...
174
+ end
175
+ ```
176
+
177
+ Here's an example of the log generated by this method:
178
+
179
+ ```
180
+ Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
181
+ Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl
182
+ vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4
183
+ Parameters: {"commit"=>"Create", "post"=>{"title"=>"Debugging Rails",
184
+ "body"=>"I'm learning how to print in logs!!!", "published"=>"0"},
185
+ "authenticity_token"=>"2059c1286e93402e389127b1153204e0d1e275dd", "action"=>"create", "controller"=>"posts"}
186
+ New post: {"updated_at"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!",
187
+ "published"=>false, "created_at"=>nil}
188
+ Post should be valid: true
189
+ Post Create (0.000443) INSERT INTO "posts" ("updated_at", "title", "body", "published",
190
+ "created_at") VALUES('2008-09-08 14:52:54', 'Debugging Rails',
191
+ 'I''m learning how to print in logs!!!', 'f', '2008-09-08 14:52:54')
192
+ The post was saved and now the user is going to be redirected...
193
+ Redirected to #<Post:0x20af760>
194
+ Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
195
+ ```
196
+
197
+ Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia.
198
+
199
+ ### Tagged Logging
200
+
201
+ When running multi-user, multi-account applications, it’s often useful to be able to filter the logs using some custom rules. `TaggedLogging` in Active Support helps in doing exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such applications.
202
+
203
+ ```ruby
204
+ logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
205
+ logger.tagged("BCX") { logger.info "Stuff" } # Logs "[BCX] Stuff"
206
+ logger.tagged("BCX", "Jason") { logger.info "Stuff" } # Logs "[BCX] [Jason] Stuff"
207
+ logger.tagged("BCX") { logger.tagged("Jason") { logger.info "Stuff" } } # Logs "[BCX] [Jason] Stuff"
208
+ ```
209
+
210
+ Debugging with the `debugger` gem
211
+ ---------------------------------
212
+
213
+ When your code is behaving in unexpected ways, you can try printing to logs or the console to diagnose the problem. Unfortunately, there are times when this sort of error tracking is not effective in finding the root cause of a problem. When you actually need to journey into your running source code, the debugger is your best companion.
214
+
215
+ The debugger can also help you if you want to learn about the Rails source code but don't know where to start. Just debug any request to your application and use this guide to learn how to move from the code you have written deeper into Rails code.
216
+
217
+ ### Setup
218
+
219
+ Rails uses the `debugger` gem to set breakpoints and step through live code. To install it, just run:
220
+
221
+ ```bash
222
+ $ gem install debugger
223
+ ```
224
+
225
+ Rails has had built-in support for debugging since Rails 2.0. Inside any Rails application you can invoke the debugger by calling the `debugger` method.
226
+
227
+ Here's an example:
228
+
229
+ ```ruby
230
+ class PeopleController < ApplicationController
231
+ def new
232
+ debugger
233
+ @person = Person.new
234
+ end
235
+ end
236
+ ```
237
+
238
+ If you see the message in the console or logs:
239
+
240
+ ```
241
+ ***** Debugger requested, but was not available: Start server with --debugger to enable *****
242
+ ```
243
+
244
+ Make sure you have started your web server with the option `--debugger`:
245
+
246
+ ```bash
247
+ $ rails server --debugger
248
+ => Booting WEBrick
249
+ => Rails 3.0.0 application starting on http://0.0.0.0:3000
250
+ => Debugger enabled
251
+ ...
252
+ ```
253
+
254
+ TIP: In development mode, you can dynamically `require \'debugger\'` instead of restarting the server, if it was started without `--debugger`.
255
+
256
+ ### The Shell
257
+
258
+ As soon as your application calls the `debugger` method, the debugger will be started in a debugger shell inside the terminal window where you launched your application server, and you will be placed at the debugger's prompt `(rdb:n)`. The _n_ is the thread number. The prompt will also show you the next line of code that is waiting to run.
259
+
260
+ If you got there by a browser request, the browser tab containing the request will be hung until the debugger has finished and the trace has finished processing the entire request.
261
+
262
+ For example:
263
+
264
+ ```bash
265
+ @posts = Post.all
266
+ (rdb:7)
267
+ ```
268
+
269
+ Now it's time to explore and dig into your application. A good place to start is by asking the debugger for help... so type: `help` (You didn't see that coming, right?)
270
+
271
+ ```
272
+ (rdb:7) help
273
+ ruby-debug help v0.10.2
274
+ Type 'help <command-name>' for help on a specific command
275
+
276
+ Available commands:
277
+ backtrace delete enable help next quit show trace
278
+ break disable eval info p reload source undisplay
279
+ catch display exit irb pp restart step up
280
+ condition down finish list ps save thread var
281
+ continue edit frame method putl set tmate where
282
+ ```
283
+
284
+ TIP: To view the help menu for any command use `help <command-name>` in active debug mode. For example: _`help var`_
285
+
286
+ The next command to learn is one of the most useful: `list`. You can abbreviate any debugging command by supplying just enough letters to distinguish them from other commands, so you can also use `l` for the `list` command.
287
+
288
+ This command shows you where you are in the code by printing 10 lines centered around the current line; the current line in this particular case is line 6 and is marked by `=>`.
289
+
290
+ ```
291
+ (rdb:7) list
292
+ [1, 10] in /PathToProject/posts_controller.rb
293
+ 1 class PostsController < ApplicationController
294
+ 2 # GET /posts
295
+ 3 # GET /posts.json
296
+ 4 def index
297
+ 5 debugger
298
+ => 6 @posts = Post.all
299
+ 7
300
+ 8 respond_to do |format|
301
+ 9 format.html # index.html.erb
302
+ 10 format.json { render :json => @posts }
303
+ ```
304
+
305
+ If you repeat the `list` command, this time using just `l`, the next ten lines of the file will be printed out.
306
+
307
+ ```
308
+ (rdb:7) l
309
+ [11, 20] in /PathTo/project/app/controllers/posts_controller.rb
310
+ 11 end
311
+ 12 end
312
+ 13
313
+ 14 # GET /posts/1
314
+ 15 # GET /posts/1.json
315
+ 16 def show
316
+ 17 @post = Post.find(params[:id])
317
+ 18
318
+ 19 respond_to do |format|
319
+ 20 format.html # show.html.erb
320
+ ```
321
+
322
+ And so on until the end of the current file. When the end of file is reached, the `list` command will start again from the beginning of the file and continue again up to the end, treating the file as a circular buffer.
323
+
324
+ On the other hand, to see the previous ten lines you should type `list-` (or `l-`)
325
+
326
+ ```
327
+ (rdb:7) l-
328
+ [1, 10] in /PathToProject/posts_controller.rb
329
+ 1 class PostsController < ApplicationController
330
+ 2 # GET /posts
331
+ 3 # GET /posts.json
332
+ 4 def index
333
+ 5 debugger
334
+ 6 @posts = Post.all
335
+ 7
336
+ 8 respond_to do |format|
337
+ 9 format.html # index.html.erb
338
+ 10 format.json { render :json => @posts }
339
+ ```
340
+
341
+ This way you can move inside the file, being able to see the code above and over the line you added the `debugger`.
342
+ Finally, to see where you are in the code again you can type `list=`
343
+
344
+ ```
345
+ (rdb:7) list=
346
+ [1, 10] in /PathToProject/posts_controller.rb
347
+ 1 class PostsController < ApplicationController
348
+ 2 # GET /posts
349
+ 3 # GET /posts.json
350
+ 4 def index
351
+ 5 debugger
352
+ => 6 @posts = Post.all
353
+ 7
354
+ 8 respond_to do |format|
355
+ 9 format.html # index.html.erb
356
+ 10 format.json { render :json => @posts }
357
+ ```
358
+
359
+ ### The Context
360
+
361
+ When you start debugging your application, you will be placed in different contexts as you go through the different parts of the stack.
362
+
363
+ The debugger creates a context when a stopping point or an event is reached. The context has information about the suspended program which enables a debugger to inspect the frame stack, evaluate variables from the perspective of the debugged program, and contains information about the place where the debugged program is stopped.
364
+
365
+ At any time you can call the `backtrace` command (or its alias `where`) to print the backtrace of the application. This can be very helpful to know how you got where you are. If you ever wondered about how you got somewhere in your code, then `backtrace` will supply the answer.
366
+
367
+ ```
368
+ (rdb:5) where
369
+ #0 PostsController.index
370
+ at line /PathTo/project/app/controllers/posts_controller.rb:6
371
+ #1 Kernel.send
372
+ at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
373
+ #2 ActionController::Base.perform_action_without_filters
374
+ at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
375
+ #3 ActionController::Filters::InstanceMethods.call_filters(chain#ActionController::Fil...,...)
376
+ at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb:617
377
+ ...
378
+ ```
379
+
380
+ You move anywhere you want in this trace (thus changing the context) by using the `frame _n_` command, where _n_ is the specified frame number.
381
+
382
+ ```
383
+ (rdb:5) frame 2
384
+ #2 ActionController::Base.perform_action_without_filters
385
+ at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
386
+ ```
387
+
388
+ The available variables are the same as if you were running the code line by line. After all, that's what debugging is.
389
+
390
+ Moving up and down the stack frame: You can use `up [n]` (`u` for abbreviated) and `down [n]` commands in order to change the context _n_ frames up or down the stack respectively. _n_ defaults to one. Up in this case is towards higher-numbered stack frames, and down is towards lower-numbered stack frames.
391
+
392
+ ### Threads
393
+
394
+ The debugger can list, stop, resume and switch between running threads by using the command `thread` (or the abbreviated `th`). This command has a handful of options:
395
+
396
+ * `thread` shows the current thread.
397
+ * `thread list` is used to list all threads and their statuses. The plus + character and the number indicates the current thread of execution.
398
+ * `thread stop _n_` stop thread _n_.
399
+ * `thread resume _n_` resumes thread _n_.
400
+ * `thread switch _n_` switches the current thread context to _n_.
401
+
402
+ This command is very helpful, among other occasions, when you are debugging concurrent threads and need to verify that there are no race conditions in your code.
403
+
404
+ ### Inspecting Variables
405
+
406
+ Any expression can be evaluated in the current context. To evaluate an expression, just type it!
407
+
408
+ This example shows how you can print the instance_variables defined within the current context:
409
+
410
+ ```
411
+ @posts = Post.all
412
+ (rdb:11) instance_variables
413
+ ["@_response", "@action_name", "@url", "@_session", "@_cookies", "@performed_render", "@_flash", "@template", "@_params", "@before_filter_chain_aborted", "@request_origin", "@_headers", "@performed_redirect", "@_request"]
414
+ ```
415
+
416
+ As you may have figured out, all of the variables that you can access from a controller are displayed. This list is dynamically updated as you execute code. For example, run the next line using `next` (you'll learn more about this command later in this guide).
417
+
418
+ ```
419
+ (rdb:11) next
420
+ Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET]
421
+ Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e
422
+ Parameters: {"action"=>"index", "controller"=>"posts"}
423
+ /PathToProject/posts_controller.rb:8
424
+ respond_to do |format|
425
+ ```
426
+
427
+ And then ask again for the instance_variables:
428
+
429
+ ```
430
+ (rdb:11) instance_variables.include? "@posts"
431
+ true
432
+ ```
433
+
434
+ Now `@posts` is included in the instance variables, because the line defining it was executed.
435
+
436
+ TIP: You can also step into **irb** mode with the command `irb` (of course!). This way an irb session will be started within the context you invoked it. But be warned: this is an experimental feature.
437
+
438
+ The `var` method is the most convenient way to show variables and their values:
439
+
440
+ ```
441
+ var
442
+ (rdb:1) v[ar] const <object> show constants of object
443
+ (rdb:1) v[ar] g[lobal] show global variables
444
+ (rdb:1) v[ar] i[nstance] <object> show instance variables of object
445
+ (rdb:1) v[ar] l[ocal] show local variables
446
+ ```
447
+
448
+ This is a great way to inspect the values of the current context variables. For example:
449
+
450
+ ```
451
+ (rdb:9) var local
452
+ __dbg_verbose_save => false
453
+ ```
454
+
455
+ You can also inspect for an object method this way:
456
+
457
+ ```
458
+ (rdb:9) var instance Post.new
459
+ @attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"...
460
+ @attributes_cache = {}
461
+ @new_record = true
462
+ ```
463
+
464
+ TIP: The commands `p` (print) and `pp` (pretty print) can be used to evaluate Ruby expressions and display the value of variables to the console.
465
+
466
+ You can use also `display` to start watching variables. This is a good way of tracking the values of a variable while the execution goes on.
467
+
468
+ ```
469
+ (rdb:1) display @recent_comments
470
+ 1: @recent_comments =
471
+ ```
472
+
473
+ The variables inside the displaying list will be printed with their values after you move in the stack. To stop displaying a variable use `undisplay _n_` where _n_ is the variable number (1 in the last example).
474
+
475
+ ### Step by Step
476
+
477
+ Now you should know where you are in the running trace and be able to print the available variables. But lets continue and move on with the application execution.
478
+
479
+ Use `step` (abbreviated `s`) to continue running your program until the next logical stopping point and return control to the debugger.
480
+
481
+ TIP: You can also use `step+ n` and `step- n` to move forward or backward `n` steps respectively.
482
+
483
+ You may also use `next` which is similar to step, but function or method calls that appear within the line of code are executed without stopping. As with step, you may use plus sign to move _n_ steps.
484
+
485
+ The difference between `next` and `step` is that `step` stops at the next line of code executed, doing just a single step, while `next` moves to the next line without descending inside methods.
486
+
487
+ For example, consider this block of code with an included `debugger` statement:
488
+
489
+ ```ruby
490
+ class Author < ActiveRecord::Base
491
+ has_one :editorial
492
+ has_many :comments
493
+
494
+ def find_recent_comments(limit = 10)
495
+ debugger
496
+ @recent_comments ||= comments.where("created_at > ?", 1.week.ago).limit(limit)
497
+ end
498
+ end
499
+ ```
500
+
501
+ TIP: You can use the debugger while using `rails console`. Just remember to `require "debugger"` before calling the `debugger` method.
502
+
503
+ ```
504
+ $ rails console
505
+ Loading development environment (Rails 3.1.0)
506
+ >> require "debugger"
507
+ => []
508
+ >> author = Author.first
509
+ => #<Author id: 1, first_name: "Bob", last_name: "Smith", created_at: "2008-07-31 12:46:10", updated_at: "2008-07-31 12:46:10">
510
+ >> author.find_recent_comments
511
+ /PathTo/project/app/models/author.rb:11
512
+ )
513
+ ```
514
+
515
+ With the code stopped, take a look around:
516
+
517
+ ```
518
+ (rdb:1) list
519
+ [2, 9] in /PathTo/project/app/models/author.rb
520
+ 2 has_one :editorial
521
+ 3 has_many :comments
522
+ 4
523
+ 5 def find_recent_comments(limit = 10)
524
+ 6 debugger
525
+ => 7 @recent_comments ||= comments.where("created_at > ?", 1.week.ago).limit(limit)
526
+ 8 end
527
+ 9 end
528
+ ```
529
+
530
+ You are at the end of the line, but... was this line executed? You can inspect the instance variables.
531
+
532
+ ```
533
+ (rdb:1) var instance
534
+ @attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
535
+ @attributes_cache = {}
536
+ ```
537
+
538
+ `@recent_comments` hasn't been defined yet, so it's clear that this line hasn't been executed yet. Use the `next` command to move on in the code:
539
+
540
+ ```
541
+ (rdb:1) next
542
+ /PathTo/project/app/models/author.rb:12
543
+ @recent_comments
544
+ (rdb:1) var instance
545
+ @attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
546
+ @attributes_cache = {}
547
+ @comments = []
548
+ @recent_comments = []
549
+ ```
550
+
551
+ Now you can see that the `@comments` relationship was loaded and @recent_comments defined because the line was executed.
552
+
553
+ If you want to go deeper into the stack trace you can move single `steps`, through your calling methods and into Rails code. This is one of the best ways to find bugs in your code, or perhaps in Ruby or Rails.
554
+
555
+ ### Breakpoints
556
+
557
+ A breakpoint makes your application stop whenever a certain point in the program is reached. The debugger shell is invoked in that line.
558
+
559
+ You can add breakpoints dynamically with the command `break` (or just `b`). There are 3 possible ways of adding breakpoints manually:
560
+
561
+ * `break line`: set breakpoint in the _line_ in the current source file.
562
+ * `break file:line [if expression]`: set breakpoint in the _line_ number inside the _file_. If an _expression_ is given it must evaluated to _true_ to fire up the debugger.
563
+ * `break class(.|\#)method [if expression]`: set breakpoint in _method_ (. and \# for class and instance method respectively) defined in _class_. The _expression_ works the same way as with file:line.
564
+
565
+ ```
566
+ (rdb:5) break 10
567
+ Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10
568
+ ```
569
+
570
+ Use `info breakpoints _n_` or `info break _n_` to list breakpoints. If you supply a number, it lists that breakpoint. Otherwise it lists all breakpoints.
571
+
572
+ ```
573
+ (rdb:5) info breakpoints
574
+ Num Enb What
575
+ 1 y at filters.rb:10
576
+ ```
577
+
578
+ To delete breakpoints: use the command `delete _n_` to remove the breakpoint number _n_. If no number is specified, it deletes all breakpoints that are currently active..
579
+
580
+ ```
581
+ (rdb:5) delete 1
582
+ (rdb:5) info breakpoints
583
+ No breakpoints.
584
+ ```
585
+
586
+ You can also enable or disable breakpoints:
587
+
588
+ * `enable breakpoints`: allow a list _breakpoints_ or all of them if no list is specified, to stop your program. This is the default state when you create a breakpoint.
589
+ * `disable breakpoints`: the _breakpoints_ will have no effect on your program.
590
+
591
+ ### Catching Exceptions
592
+
593
+ The command `catch exception-name` (or just `cat exception-name`) can be used to intercept an exception of type _exception-name_ when there would otherwise be is no handler for it.
594
+
595
+ To list all active catchpoints use `catch`.
596
+
597
+ ### Resuming Execution
598
+
599
+ There are two ways to resume execution of an application that is stopped in the debugger:
600
+
601
+ * `continue` [line-specification] \(or `c`): resume program execution, at the address where your script last stopped; any breakpoints set at that address are bypassed. The optional argument line-specification allows you to specify a line number to set a one-time breakpoint which is deleted when that breakpoint is reached.
602
+ * `finish` [frame-number] \(or `fin`): execute until the selected stack frame returns. If no frame number is given, the application will run until the currently selected frame returns. The currently selected frame starts out the most-recent frame or 0 if no frame positioning (e.g up, down or frame) has been performed. If a frame number is given it will run until the specified frame returns.
603
+
604
+ ### Editing
605
+
606
+ Two commands allow you to open code from the debugger into an editor:
607
+
608
+ * `edit [file:line]`: edit _file_ using the editor specified by the EDITOR environment variable. A specific _line_ can also be given.
609
+ * `tmate _n_` (abbreviated `tm`): open the current file in TextMate. It uses n-th frame if _n_ is specified.
610
+
611
+ ### Quitting
612
+
613
+ To exit the debugger, use the `quit` command (abbreviated `q`), or its alias `exit`.
614
+
615
+ A simple quit tries to terminate all threads in effect. Therefore your server will be stopped and you will have to start it again.
616
+
617
+ ### Settings
618
+
619
+ The `debugger` gem can automatically show the code you're stepping through and reload it when you change it in an editor. Here are a few of the available options:
620
+
621
+ * `set reload`: Reload source code when changed.
622
+ * `set autolist`: Execute `list` command on every breakpoint.
623
+ * `set listsize _n_`: Set number of source lines to list by default to _n_.
624
+ * `set forcestep`: Make sure the `next` and `step` commands always move to a new line
625
+
626
+ You can see the full list by using `help set`. Use `help set _subcommand_` to learn about a particular `set` command.
627
+
628
+ TIP: You can save these settings in an `.rdebugrc` file in your home directory. The debugger reads these global settings when it starts.
629
+
630
+ Here's a good start for an `.rdebugrc`:
631
+
632
+ ```bash
633
+ set autolist
634
+ set forcestep
635
+ set listsize 25
636
+ ```
637
+
638
+ Debugging Memory Leaks
639
+ ----------------------
640
+
641
+ A Ruby application (on Rails or not), can leak memory - either in the Ruby code or at the C code level.
642
+
643
+ In this section, you will learn how to find and fix such leaks by using tool such as Valgrind.
644
+
645
+ ### Valgrind
646
+
647
+ [Valgrind](http://valgrind.org/) is a Linux-only application for detecting C-based memory leaks and race conditions.
648
+
649
+ There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. For example, a C extension in the interpreter calls `malloc()` but is doesn't properly call `free()`, this memory won't be available until the app terminates.
650
+
651
+ For further information on how to install Valgrind and use with Ruby, refer to [Valgrind and Ruby](http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/) by Evan Weaver.
652
+
653
+ Plugins for Debugging
654
+ ---------------------
655
+
656
+ There are some Rails plugins to help you to find errors and debug your application. Here is a list of useful plugins for debugging:
657
+
658
+ * [Footnotes](https://github.com/josevalim/rails-footnotes:) Every Rails page has footnotes that give request information and link back to your source via TextMate.
659
+ * [Query Trace](https://github.com/ntalbott/query_trace/tree/master:) Adds query origin tracing to your logs.
660
+ * [Query Reviewer](https://github.com/nesquena/query_reviewer:) This rails plugin not only runs "EXPLAIN" before each of your select queries in development, but provides a small DIV in the rendered output of each page with the summary of warnings for each query that it analyzed.
661
+ * [Exception Notifier](https://github.com/smartinez87/exception_notification/tree/master:) Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application.
662
+
663
+ References
664
+ ----------
665
+
666
+ * [ruby-debug Homepage](http://bashdb.sourceforge.net/ruby-debug/home-page.html)
667
+ * [debugger Homepage](https://github.com/cldwalker/debugger)
668
+ * [Article: Debugging a Rails application with ruby-debug](http://www.sitepoint.com/article/debug-rails-app-ruby-debug/)
669
+ * [ruby-debug Basics screencast](http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/)
670
+ * [Ryan Bates' debugging ruby (revised) screencast](http://railscasts.com/episodes/54-debugging-ruby-revised)
671
+ * [Ryan Bates' stack trace screencast](http://railscasts.com/episodes/24-the-stack-trace)
672
+ * [Ryan Bates' logger screencast](http://railscasts.com/episodes/56-the-logger)
673
+ * [Debugging with ruby-debug](http://bashdb.sourceforge.net/ruby-debug.html)
674
+ * [ruby-debug cheat sheet](http://cheat.errtheblog.com/s/rdebug/)
675
+ * [Ruby on Rails Wiki: How to Configure Logging](http://wiki.rubyonrails.org/rails/pages/HowtoConfigureLogging)