rails 4.1.4 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -18
  3. metadata +51 -304
  4. data/guides/CHANGELOG.md +0 -41
  5. data/guides/Rakefile +0 -77
  6. data/guides/assets/images/akshaysurve.jpg +0 -0
  7. data/guides/assets/images/belongs_to.png +0 -0
  8. data/guides/assets/images/book_icon.gif +0 -0
  9. data/guides/assets/images/bullet.gif +0 -0
  10. data/guides/assets/images/chapters_icon.gif +0 -0
  11. data/guides/assets/images/check_bullet.gif +0 -0
  12. data/guides/assets/images/credits_pic_blank.gif +0 -0
  13. data/guides/assets/images/csrf.png +0 -0
  14. data/guides/assets/images/edge_badge.png +0 -0
  15. data/guides/assets/images/favicon.ico +0 -0
  16. data/guides/assets/images/feature_tile.gif +0 -0
  17. data/guides/assets/images/footer_tile.gif +0 -0
  18. data/guides/assets/images/fxn.png +0 -0
  19. data/guides/assets/images/getting_started/article_with_comments.png +0 -0
  20. data/guides/assets/images/getting_started/challenge.png +0 -0
  21. data/guides/assets/images/getting_started/confirm_dialog.png +0 -0
  22. data/guides/assets/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  23. data/guides/assets/images/getting_started/form_with_errors.png +0 -0
  24. data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
  25. data/guides/assets/images/getting_started/new_article.png +0 -0
  26. data/guides/assets/images/getting_started/rails_welcome.png +0 -0
  27. data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
  28. data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
  29. data/guides/assets/images/getting_started/show_action_for_articles.png +0 -0
  30. data/guides/assets/images/getting_started/template_is_missing_articles_new.png +0 -0
  31. data/guides/assets/images/getting_started/unknown_action_create_for_articles.png +0 -0
  32. data/guides/assets/images/getting_started/unknown_action_new_for_articles.png +0 -0
  33. data/guides/assets/images/grey_bullet.gif +0 -0
  34. data/guides/assets/images/habtm.png +0 -0
  35. data/guides/assets/images/has_many.png +0 -0
  36. data/guides/assets/images/has_many_through.png +0 -0
  37. data/guides/assets/images/has_one.png +0 -0
  38. data/guides/assets/images/has_one_through.png +0 -0
  39. data/guides/assets/images/header_backdrop.png +0 -0
  40. data/guides/assets/images/header_tile.gif +0 -0
  41. data/guides/assets/images/i18n/demo_html_safe.png +0 -0
  42. data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
  43. data/guides/assets/images/i18n/demo_translated_en.png +0 -0
  44. data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
  45. data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
  46. data/guides/assets/images/i18n/demo_untranslated.png +0 -0
  47. data/guides/assets/images/icons/README +0 -5
  48. data/guides/assets/images/icons/callouts/1.png +0 -0
  49. data/guides/assets/images/icons/callouts/10.png +0 -0
  50. data/guides/assets/images/icons/callouts/11.png +0 -0
  51. data/guides/assets/images/icons/callouts/12.png +0 -0
  52. data/guides/assets/images/icons/callouts/13.png +0 -0
  53. data/guides/assets/images/icons/callouts/14.png +0 -0
  54. data/guides/assets/images/icons/callouts/15.png +0 -0
  55. data/guides/assets/images/icons/callouts/2.png +0 -0
  56. data/guides/assets/images/icons/callouts/3.png +0 -0
  57. data/guides/assets/images/icons/callouts/4.png +0 -0
  58. data/guides/assets/images/icons/callouts/5.png +0 -0
  59. data/guides/assets/images/icons/callouts/6.png +0 -0
  60. data/guides/assets/images/icons/callouts/7.png +0 -0
  61. data/guides/assets/images/icons/callouts/8.png +0 -0
  62. data/guides/assets/images/icons/callouts/9.png +0 -0
  63. data/guides/assets/images/icons/caution.png +0 -0
  64. data/guides/assets/images/icons/example.png +0 -0
  65. data/guides/assets/images/icons/home.png +0 -0
  66. data/guides/assets/images/icons/important.png +0 -0
  67. data/guides/assets/images/icons/next.png +0 -0
  68. data/guides/assets/images/icons/note.png +0 -0
  69. data/guides/assets/images/icons/prev.png +0 -0
  70. data/guides/assets/images/icons/tip.png +0 -0
  71. data/guides/assets/images/icons/up.png +0 -0
  72. data/guides/assets/images/icons/warning.png +0 -0
  73. data/guides/assets/images/nav_arrow.gif +0 -0
  74. data/guides/assets/images/oscardelben.jpg +0 -0
  75. data/guides/assets/images/polymorphic.png +0 -0
  76. data/guides/assets/images/radar.png +0 -0
  77. data/guides/assets/images/rails4_features.png +0 -0
  78. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  79. data/guides/assets/images/rails_guides_logo.gif +0 -0
  80. data/guides/assets/images/rails_logo_remix.gif +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 +0 -53
  90. data/guides/assets/javascripts/jquery.min.js +0 -4
  91. data/guides/assets/javascripts/responsive-tables.js +0 -43
  92. data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
  93. data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
  94. data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
  95. data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
  96. data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
  97. data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
  98. data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
  99. data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
  100. data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
  101. data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
  102. data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
  103. data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
  104. data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
  105. data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
  106. data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
  107. data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
  108. data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
  109. data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
  110. data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
  111. data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
  112. data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
  113. data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
  114. data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
  115. data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
  116. data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
  117. data/guides/assets/javascripts/syntaxhighlighter/shCore.js +0 -17
  118. data/guides/assets/stylesheets/fixes.css +0 -16
  119. data/guides/assets/stylesheets/kindle.css +0 -11
  120. data/guides/assets/stylesheets/main.css +0 -710
  121. data/guides/assets/stylesheets/print.css +0 -52
  122. data/guides/assets/stylesheets/reset.css +0 -43
  123. data/guides/assets/stylesheets/responsive-tables.css +0 -50
  124. data/guides/assets/stylesheets/style.css +0 -13
  125. data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +0 -226
  126. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
  127. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
  128. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
  129. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
  130. data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  131. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
  132. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
  133. data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
  134. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
  135. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
  136. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
  137. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
  138. data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  139. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
  140. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
  141. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
  142. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
  143. data/guides/bug_report_templates/action_controller_gem.rb +0 -47
  144. data/guides/bug_report_templates/action_controller_master.rb +0 -53
  145. data/guides/bug_report_templates/active_record_gem.rb +0 -40
  146. data/guides/bug_report_templates/active_record_master.rb +0 -49
  147. data/guides/code/getting_started/Gemfile +0 -40
  148. data/guides/code/getting_started/Gemfile.lock +0 -125
  149. data/guides/code/getting_started/README.rdoc +0 -28
  150. data/guides/code/getting_started/Rakefile +0 -6
  151. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  152. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  153. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  154. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  155. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  156. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  157. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  158. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  159. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  160. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  161. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  162. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  163. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  164. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  165. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  166. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  167. data/guides/code/getting_started/app/models/comment.rb +0 -3
  168. data/guides/code/getting_started/app/models/post.rb +0 -7
  169. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  170. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  171. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  172. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  173. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  174. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  175. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  176. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  177. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  178. data/guides/code/getting_started/bin/bundle +0 -4
  179. data/guides/code/getting_started/bin/rails +0 -4
  180. data/guides/code/getting_started/bin/rake +0 -4
  181. data/guides/code/getting_started/config/application.rb +0 -18
  182. data/guides/code/getting_started/config/boot.rb +0 -4
  183. data/guides/code/getting_started/config/database.yml +0 -25
  184. data/guides/code/getting_started/config/environment.rb +0 -5
  185. data/guides/code/getting_started/config/environments/development.rb +0 -30
  186. data/guides/code/getting_started/config/environments/production.rb +0 -80
  187. data/guides/code/getting_started/config/environments/test.rb +0 -36
  188. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  189. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  190. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  191. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  192. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  193. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  194. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  195. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  196. data/guides/code/getting_started/config/locales/en.yml +0 -23
  197. data/guides/code/getting_started/config/routes.rb +0 -7
  198. data/guides/code/getting_started/config.ru +0 -4
  199. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  200. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  201. data/guides/code/getting_started/db/schema.rb +0 -33
  202. data/guides/code/getting_started/db/seeds.rb +0 -7
  203. data/guides/code/getting_started/public/404.html +0 -60
  204. data/guides/code/getting_started/public/422.html +0 -60
  205. data/guides/code/getting_started/public/500.html +0 -59
  206. data/guides/code/getting_started/public/favicon.ico +0 -0
  207. data/guides/code/getting_started/public/robots.txt +0 -5
  208. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  209. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  210. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  211. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  212. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  213. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  214. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  215. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  216. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  217. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  218. data/guides/code/getting_started/test/test_helper.rb +0 -12
  219. data/guides/rails_guides/generator.rb +0 -248
  220. data/guides/rails_guides/helpers.rb +0 -53
  221. data/guides/rails_guides/indexer.rb +0 -68
  222. data/guides/rails_guides/kindle.rb +0 -119
  223. data/guides/rails_guides/levenshtein.rb +0 -31
  224. data/guides/rails_guides/markdown/renderer.rb +0 -82
  225. data/guides/rails_guides/markdown.rb +0 -163
  226. data/guides/rails_guides.rb +0 -63
  227. data/guides/source/2_2_release_notes.md +0 -435
  228. data/guides/source/2_3_release_notes.md +0 -621
  229. data/guides/source/3_0_release_notes.md +0 -611
  230. data/guides/source/3_1_release_notes.md +0 -556
  231. data/guides/source/3_2_release_notes.md +0 -565
  232. data/guides/source/4_0_release_notes.md +0 -276
  233. data/guides/source/4_1_release_notes.md +0 -731
  234. data/guides/source/_license.html.erb +0 -2
  235. data/guides/source/_welcome.html.erb +0 -25
  236. data/guides/source/action_controller_overview.md +0 -1175
  237. data/guides/source/action_mailer_basics.md +0 -689
  238. data/guides/source/action_view_overview.md +0 -1610
  239. data/guides/source/active_model_basics.md +0 -200
  240. data/guides/source/active_record_basics.md +0 -373
  241. data/guides/source/active_record_callbacks.md +0 -410
  242. data/guides/source/active_record_querying.md +0 -1773
  243. data/guides/source/active_record_validations.md +0 -1169
  244. data/guides/source/active_support_core_extensions.md +0 -3864
  245. data/guides/source/active_support_instrumentation.md +0 -496
  246. data/guides/source/api_documentation_guidelines.md +0 -315
  247. data/guides/source/asset_pipeline.md +0 -1163
  248. data/guides/source/association_basics.md +0 -2229
  249. data/guides/source/caching_with_rails.md +0 -354
  250. data/guides/source/command_line.md +0 -603
  251. data/guides/source/configuring.md +0 -942
  252. data/guides/source/contributing_to_ruby_on_rails.md +0 -544
  253. data/guides/source/credits.html.erb +0 -80
  254. data/guides/source/debugging_rails_applications.md +0 -707
  255. data/guides/source/development_dependencies_install.md +0 -278
  256. data/guides/source/documents.yaml +0 -193
  257. data/guides/source/engines.md +0 -1391
  258. data/guides/source/form_helpers.md +0 -1001
  259. data/guides/source/generators.md +0 -663
  260. data/guides/source/getting_started.md +0 -1947
  261. data/guides/source/i18n.md +0 -1043
  262. data/guides/source/index.html.erb +0 -27
  263. data/guides/source/initialization.md +0 -657
  264. data/guides/source/kindle/copyright.html.erb +0 -1
  265. data/guides/source/kindle/layout.html.erb +0 -27
  266. data/guides/source/kindle/rails_guides.opf.erb +0 -52
  267. data/guides/source/kindle/toc.html.erb +0 -24
  268. data/guides/source/kindle/toc.ncx.erb +0 -64
  269. data/guides/source/kindle/welcome.html.erb +0 -5
  270. data/guides/source/layout.html.erb +0 -146
  271. data/guides/source/layouts_and_rendering.md +0 -1226
  272. data/guides/source/maintenance_policy.md +0 -56
  273. data/guides/source/migrations.md +0 -1109
  274. data/guides/source/nested_model_forms.md +0 -225
  275. data/guides/source/plugins.md +0 -444
  276. data/guides/source/rails_application_templates.md +0 -248
  277. data/guides/source/rails_on_rack.md +0 -333
  278. data/guides/source/routing.md +0 -1115
  279. data/guides/source/ruby_on_rails_guides_guidelines.md +0 -128
  280. data/guides/source/security.md +0 -1018
  281. data/guides/source/testing.md +0 -1052
  282. data/guides/source/upgrading_ruby_on_rails.md +0 -899
  283. data/guides/source/working_with_javascript_in_rails.md +0 -405
  284. data/guides/w3c_validator.rb +0 -95
@@ -1,707 +0,0 @@
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 when this controller action is executed:
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
202
- to be able to filter the logs using some custom rules. `TaggedLogging`
203
- in Active Support helps in doing exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such applications.
204
-
205
- ```ruby
206
- logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
207
- logger.tagged("BCX") { logger.info "Stuff" } # Logs "[BCX] Stuff"
208
- logger.tagged("BCX", "Jason") { logger.info "Stuff" } # Logs "[BCX] [Jason] Stuff"
209
- logger.tagged("BCX") { logger.tagged("Jason") { logger.info "Stuff" } } # Logs "[BCX] [Jason] Stuff"
210
- ```
211
-
212
- ### Impact of Logs on Performance
213
- Logging will always have a small impact on performance of your rails app,
214
- particularly when logging to disk.However, there are a few subtleties:
215
-
216
- Using the `:debug` level will have a greater performance penalty than `:fatal`,
217
- as a far greater number of strings are being evaluated and written to the
218
- log output (e.g. disk).
219
-
220
- Another potential pitfall is that if you have many calls to `Logger` like this
221
- in your code:
222
-
223
- ```ruby
224
- logger.debug "Person attributes hash: #{@person.attributes.inspect}"
225
- ```
226
-
227
- In the above example, There will be a performance impact even if the allowed
228
- output level doesn't include debug. The reason is that Ruby has to evaluate
229
- these strings, which includes instantiating the somewhat heavy `String` object
230
- and interpolating the variables, and which takes time.
231
- Therefore, it's recommended to pass blocks to the logger methods, as these are
232
- only evaluated if the output level is the same or included in the allowed level
233
- (i.e. lazy loading). The same code rewritten would be:
234
-
235
- ```ruby
236
- logger.debug {"Person attributes hash: #{@person.attributes.inspect}"}
237
- ```
238
-
239
- The contents of the block, and therefore the string interpolation, is only
240
- evaluated if debug is enabled. This performance savings is only really
241
- noticeable with large amounts of logging, but it's a good practice to employ.
242
-
243
- Debugging with the `debugger` gem
244
- ---------------------------------
245
-
246
- 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.
247
-
248
- 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.
249
-
250
- ### Setup
251
-
252
- You can use the `debugger` gem to set breakpoints and step through live code in Rails. To install it, just run:
253
-
254
- ```bash
255
- $ gem install debugger
256
- ```
257
-
258
- 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.
259
-
260
- Here's an example:
261
-
262
- ```ruby
263
- class PeopleController < ApplicationController
264
- def new
265
- debugger
266
- @person = Person.new
267
- end
268
- end
269
- ```
270
-
271
- If you see this message in the console or logs:
272
-
273
- ```
274
- ***** Debugger requested, but was not available: Start server with --debugger to enable *****
275
- ```
276
-
277
- Make sure you have started your web server with the option `--debugger`:
278
-
279
- ```bash
280
- $ rails server --debugger
281
- => Booting WEBrick
282
- => Rails 4.1.1 application starting on http://0.0.0.0:3000
283
- => Debugger enabled
284
- ...
285
- ```
286
-
287
- TIP: In development mode, you can dynamically `require \'debugger\'` instead of restarting the server, even if it was started without `--debugger`.
288
-
289
- ### The Shell
290
-
291
- 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.
292
-
293
- 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.
294
-
295
- For example:
296
-
297
- ```bash
298
- @posts = Post.all
299
- (rdb:7)
300
- ```
301
-
302
- Now it's time to explore and dig into your application. A good place to start is by asking the debugger for help. Type: `help`
303
-
304
- ```
305
- (rdb:7) help
306
- ruby-debug help v0.10.2
307
- Type 'help <command-name>' for help on a specific command
308
-
309
- Available commands:
310
- backtrace delete enable help next quit show trace
311
- break disable eval info p reload source undisplay
312
- catch display exit irb pp restart step up
313
- condition down finish list ps save thread var
314
- continue edit frame method putl set tmate where
315
- ```
316
-
317
- TIP: To view the help menu for any command use `help <command-name>` at the debugger prompt. For example: _`help var`_
318
-
319
- 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.
320
-
321
- 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 `=>`.
322
-
323
- ```
324
- (rdb:7) list
325
- [1, 10] in /PathTo/project/app/controllers/posts_controller.rb
326
- 1 class PostsController < ApplicationController
327
- 2 # GET /posts
328
- 3 # GET /posts.json
329
- 4 def index
330
- 5 debugger
331
- => 6 @posts = Post.all
332
- 7
333
- 8 respond_to do |format|
334
- 9 format.html # index.html.erb
335
- 10 format.json { render json: @posts }
336
- ```
337
-
338
- If you repeat the `list` command, this time using just `l`, the next ten lines of the file will be printed out.
339
-
340
- ```
341
- (rdb:7) l
342
- [11, 20] in /PathTo/project/app/controllers/posts_controller.rb
343
- 11 end
344
- 12 end
345
- 13
346
- 14 # GET /posts/1
347
- 15 # GET /posts/1.json
348
- 16 def show
349
- 17 @post = Post.find(params[:id])
350
- 18
351
- 19 respond_to do |format|
352
- 20 format.html # show.html.erb
353
- ```
354
-
355
- 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.
356
-
357
- On the other hand, to see the previous ten lines you should type `list-` (or `l-`)
358
-
359
- ```
360
- (rdb:7) l-
361
- [1, 10] in /PathTo/project/app/controllers/posts_controller.rb
362
- 1 class PostsController < ApplicationController
363
- 2 # GET /posts
364
- 3 # GET /posts.json
365
- 4 def index
366
- 5 debugger
367
- 6 @posts = Post.all
368
- 7
369
- 8 respond_to do |format|
370
- 9 format.html # index.html.erb
371
- 10 format.json { render json: @posts }
372
- ```
373
-
374
- This way you can move inside the file, being able to see the code above and over the line you added the `debugger`.
375
- Finally, to see where you are in the code again you can type `list=`
376
-
377
- ```
378
- (rdb:7) list=
379
- [1, 10] in /PathTo/project/app/controllers/posts_controller.rb
380
- 1 class PostsController < ApplicationController
381
- 2 # GET /posts
382
- 3 # GET /posts.json
383
- 4 def index
384
- 5 debugger
385
- => 6 @posts = Post.all
386
- 7
387
- 8 respond_to do |format|
388
- 9 format.html # index.html.erb
389
- 10 format.json { render json: @posts }
390
- ```
391
-
392
- ### The Context
393
-
394
- When you start debugging your application, you will be placed in different contexts as you go through the different parts of the stack.
395
-
396
- 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.
397
-
398
- 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.
399
-
400
- ```
401
- (rdb:5) where
402
- #0 PostsController.index
403
- at line /PathTo/project/app/controllers/posts_controller.rb:6
404
- #1 Kernel.send
405
- at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
406
- #2 ActionController::Base.perform_action_without_filters
407
- at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
408
- #3 ActionController::Filters::InstanceMethods.call_filters(chain#ActionController::Fil...,...)
409
- at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb:617
410
- ...
411
- ```
412
-
413
- 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.
414
-
415
- ```
416
- (rdb:5) frame 2
417
- #2 ActionController::Base.perform_action_without_filters
418
- at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
419
- ```
420
-
421
- The available variables are the same as if you were running the code line by line. After all, that's what debugging is.
422
-
423
- 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.
424
-
425
- ### Threads
426
-
427
- 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:
428
-
429
- * `thread` shows the current thread.
430
- * `thread list` is used to list all threads and their statuses. The plus + character and the number indicates the current thread of execution.
431
- * `thread stop _n_` stop thread _n_.
432
- * `thread resume _n_` resumes thread _n_.
433
- * `thread switch _n_` switches the current thread context to _n_.
434
-
435
- 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.
436
-
437
- ### Inspecting Variables
438
-
439
- Any expression can be evaluated in the current context. To evaluate an expression, just type it!
440
-
441
- This example shows how you can print the instance_variables defined within the current context:
442
-
443
- ```
444
- @posts = Post.all
445
- (rdb:11) instance_variables
446
- ["@_response", "@action_name", "@url", "@_session", "@_cookies", "@performed_render", "@_flash", "@template", "@_params", "@before_filter_chain_aborted", "@request_origin", "@_headers", "@performed_redirect", "@_request"]
447
- ```
448
-
449
- 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).
450
-
451
- ```
452
- (rdb:11) next
453
- Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET]
454
- Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e
455
- Parameters: {"action"=>"index", "controller"=>"posts"}
456
- /PathToProject/posts_controller.rb:8
457
- respond_to do |format|
458
- ```
459
-
460
- And then ask again for the instance_variables:
461
-
462
- ```
463
- (rdb:11) instance_variables.include? "@posts"
464
- true
465
- ```
466
-
467
- Now `@posts` is included in the instance variables, because the line defining it was executed.
468
-
469
- 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.
470
-
471
- The `var` method is the most convenient way to show variables and their values:
472
-
473
- ```
474
- var
475
- (rdb:1) v[ar] const <object> show constants of object
476
- (rdb:1) v[ar] g[lobal] show global variables
477
- (rdb:1) v[ar] i[nstance] <object> show instance variables of object
478
- (rdb:1) v[ar] l[ocal] show local variables
479
- ```
480
-
481
- This is a great way to inspect the values of the current context variables. For example:
482
-
483
- ```
484
- (rdb:9) var local
485
- __dbg_verbose_save => false
486
- ```
487
-
488
- You can also inspect for an object method this way:
489
-
490
- ```
491
- (rdb:9) var instance Post.new
492
- @attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"...
493
- @attributes_cache = {}
494
- @new_record = true
495
- ```
496
-
497
- 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.
498
-
499
- 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.
500
-
501
- ```
502
- (rdb:1) display @recent_comments
503
- 1: @recent_comments =
504
- ```
505
-
506
- 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).
507
-
508
- ### Step by Step
509
-
510
- 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.
511
-
512
- Use `step` (abbreviated `s`) to continue running your program until the next logical stopping point and return control to the debugger.
513
-
514
- TIP: You can also use `step+ n` and `step- n` to move forward or backward `n` steps respectively.
515
-
516
- 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.
517
-
518
- 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.
519
-
520
- For example, consider this block of code with an included `debugger` statement:
521
-
522
- ```ruby
523
- class Author < ActiveRecord::Base
524
- has_one :editorial
525
- has_many :comments
526
-
527
- def find_recent_comments(limit = 10)
528
- debugger
529
- @recent_comments ||= comments.where("created_at > ?", 1.week.ago).limit(limit)
530
- end
531
- end
532
- ```
533
-
534
- TIP: You can use the debugger while using `rails console`. Just remember to `require "debugger"` before calling the `debugger` method.
535
-
536
- ```
537
- $ rails console
538
- Loading development environment (Rails 4.1.1)
539
- >> require "debugger"
540
- => []
541
- >> author = Author.first
542
- => #<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">
543
- >> author.find_recent_comments
544
- /PathTo/project/app/models/author.rb:11
545
- )
546
- ```
547
-
548
- With the code stopped, take a look around:
549
-
550
- ```
551
- (rdb:1) list
552
- [2, 9] in /PathTo/project/app/models/author.rb
553
- 2 has_one :editorial
554
- 3 has_many :comments
555
- 4
556
- 5 def find_recent_comments(limit = 10)
557
- 6 debugger
558
- => 7 @recent_comments ||= comments.where("created_at > ?", 1.week.ago).limit(limit)
559
- 8 end
560
- 9 end
561
- ```
562
-
563
- You are at the end of the line, but... was this line executed? You can inspect the instance variables.
564
-
565
- ```
566
- (rdb:1) var instance
567
- @attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
568
- @attributes_cache = {}
569
- ```
570
-
571
- `@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:
572
-
573
- ```
574
- (rdb:1) next
575
- /PathTo/project/app/models/author.rb:12
576
- @recent_comments
577
- (rdb:1) var instance
578
- @attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
579
- @attributes_cache = {}
580
- @comments = []
581
- @recent_comments = []
582
- ```
583
-
584
- Now you can see that the `@comments` relationship was loaded and @recent_comments defined because the line was executed.
585
-
586
- 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.
587
-
588
- ### Breakpoints
589
-
590
- A breakpoint makes your application stop whenever a certain point in the program is reached. The debugger shell is invoked in that line.
591
-
592
- You can add breakpoints dynamically with the command `break` (or just `b`). There are 3 possible ways of adding breakpoints manually:
593
-
594
- * `break line`: set breakpoint in the _line_ in the current source file.
595
- * `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.
596
- * `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.
597
-
598
- ```
599
- (rdb:5) break 10
600
- Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10
601
- ```
602
-
603
- 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.
604
-
605
- ```
606
- (rdb:5) info breakpoints
607
- Num Enb What
608
- 1 y at filters.rb:10
609
- ```
610
-
611
- 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..
612
-
613
- ```
614
- (rdb:5) delete 1
615
- (rdb:5) info breakpoints
616
- No breakpoints.
617
- ```
618
-
619
- You can also enable or disable breakpoints:
620
-
621
- * `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.
622
- * `disable breakpoints`: the _breakpoints_ will have no effect on your program.
623
-
624
- ### Catching Exceptions
625
-
626
- 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.
627
-
628
- To list all active catchpoints use `catch`.
629
-
630
- ### Resuming Execution
631
-
632
- There are two ways to resume execution of an application that is stopped in the debugger:
633
-
634
- * `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.
635
- * `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.
636
-
637
- ### Editing
638
-
639
- Two commands allow you to open code from the debugger into an editor:
640
-
641
- * `edit [file:line]`: edit _file_ using the editor specified by the EDITOR environment variable. A specific _line_ can also be given.
642
- * `tmate _n_` (abbreviated `tm`): open the current file in TextMate. It uses n-th frame if _n_ is specified.
643
-
644
- ### Quitting
645
-
646
- To exit the debugger, use the `quit` command (abbreviated `q`), or its alias `exit`.
647
-
648
- A simple quit tries to terminate all threads in effect. Therefore your server will be stopped and you will have to start it again.
649
-
650
- ### Settings
651
-
652
- 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:
653
-
654
- * `set reload`: Reload source code when changed.
655
- * `set autolist`: Execute `list` command on every breakpoint.
656
- * `set listsize _n_`: Set number of source lines to list by default to _n_.
657
- * `set forcestep`: Make sure the `next` and `step` commands always move to a new line
658
-
659
- You can see the full list by using `help set`. Use `help set _subcommand_` to learn about a particular `set` command.
660
-
661
- TIP: You can save these settings in an `.rdebugrc` file in your home directory. The debugger reads these global settings when it starts.
662
-
663
- Here's a good start for an `.rdebugrc`:
664
-
665
- ```bash
666
- set autolist
667
- set forcestep
668
- set listsize 25
669
- ```
670
-
671
- Debugging Memory Leaks
672
- ----------------------
673
-
674
- A Ruby application (on Rails or not), can leak memory - either in the Ruby code or at the C code level.
675
-
676
- In this section, you will learn how to find and fix such leaks by using tool such as Valgrind.
677
-
678
- ### Valgrind
679
-
680
- [Valgrind](http://valgrind.org/) is a Linux-only application for detecting C-based memory leaks and race conditions.
681
-
682
- There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. For example, if a C extension in the interpreter calls `malloc()` but doesn't properly call `free()`, this memory won't be available until the app terminates.
683
-
684
- 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.
685
-
686
- Plugins for Debugging
687
- ---------------------
688
-
689
- There are some Rails plugins to help you to find errors and debug your application. Here is a list of useful plugins for debugging:
690
-
691
- * [Footnotes](https://github.com/josevalim/rails-footnotes) Every Rails page has footnotes that give request information and link back to your source via TextMate.
692
- * [Query Trace](https://github.com/ntalbott/query_trace/tree/master) Adds query origin tracing to your logs.
693
- * [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.
694
- * [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.
695
- * [Better Errors](https://github.com/charliesome/better_errors) Replaces the standard Rails error page with a new one containing more contextual information, like source code and variable inspection.
696
- * [RailsPanel](https://github.com/dejan/rails_panel) Chrome extension for Rails development that will end your tailing of development.log. Have all information about your Rails app requests in the browser - in the Developer Tools panel. Provides insight to db/rendering/total times, parameter list, rendered views and more.
697
-
698
- References
699
- ----------
700
-
701
- * [ruby-debug Homepage](http://bashdb.sourceforge.net/ruby-debug/home-page.html)
702
- * [debugger Homepage](https://github.com/cldwalker/debugger)
703
- * [Article: Debugging a Rails application with ruby-debug](http://www.sitepoint.com/debug-rails-app-ruby-debug/)
704
- * [Ryan Bates' debugging ruby (revised) screencast](http://railscasts.com/episodes/54-debugging-ruby-revised)
705
- * [Ryan Bates' stack trace screencast](http://railscasts.com/episodes/24-the-stack-trace)
706
- * [Ryan Bates' logger screencast](http://railscasts.com/episodes/56-the-logger)
707
- * [Debugging with ruby-debug](http://bashdb.sourceforge.net/ruby-debug.html)