rails 4.1.16 → 4.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/guides/CHANGELOG.md +13 -102
  4. data/guides/Rakefile +2 -2
  5. data/guides/assets/javascripts/guides.js +6 -0
  6. data/guides/assets/stylesheets/main.css +4 -1
  7. data/guides/bug_report_templates/action_controller_gem.rb +2 -2
  8. data/guides/bug_report_templates/action_controller_master.rb +5 -2
  9. data/guides/bug_report_templates/active_record_master.rb +2 -0
  10. data/guides/rails_guides.rb +2 -2
  11. data/guides/rails_guides/helpers.rb +1 -1
  12. data/guides/rails_guides/levenshtein.rb +29 -21
  13. data/guides/rails_guides/markdown.rb +6 -7
  14. data/guides/rails_guides/markdown/renderer.rb +1 -1
  15. data/guides/source/2_3_release_notes.md +3 -3
  16. data/guides/source/3_0_release_notes.md +4 -4
  17. data/guides/source/3_1_release_notes.md +2 -2
  18. data/guides/source/3_2_release_notes.md +2 -2
  19. data/guides/source/4_1_release_notes.md +8 -9
  20. data/guides/source/4_2_release_notes.md +572 -0
  21. data/guides/source/_license.html.erb +1 -1
  22. data/guides/source/_welcome.html.erb +2 -8
  23. data/guides/source/action_controller_overview.md +79 -7
  24. data/guides/source/action_mailer_basics.md +36 -11
  25. data/guides/source/action_view_overview.md +138 -119
  26. data/guides/source/active_job_basics.md +253 -0
  27. data/guides/source/active_model_basics.md +23 -0
  28. data/guides/source/active_record_basics.md +16 -15
  29. data/guides/source/active_record_callbacks.md +12 -9
  30. data/guides/source/{migrations.md → active_record_migrations.md} +90 -217
  31. data/guides/source/active_record_postgresql.md +437 -0
  32. data/guides/source/active_record_querying.md +261 -261
  33. data/guides/source/active_record_validations.md +7 -7
  34. data/guides/source/active_support_core_extensions.md +105 -44
  35. data/guides/source/active_support_instrumentation.md +3 -2
  36. data/guides/source/api_documentation_guidelines.md +62 -16
  37. data/guides/source/asset_pipeline.md +58 -46
  38. data/guides/source/association_basics.md +47 -38
  39. data/guides/source/caching_with_rails.md +31 -6
  40. data/guides/source/command_line.md +56 -25
  41. data/guides/source/configuring.md +98 -19
  42. data/guides/source/contributing_to_ruby_on_rails.md +174 -111
  43. data/guides/source/credits.html.erb +1 -1
  44. data/guides/source/debugging_rails_applications.md +438 -284
  45. data/guides/source/development_dependencies_install.md +17 -4
  46. data/guides/source/documents.yaml +11 -7
  47. data/guides/source/engines.md +192 -203
  48. data/guides/source/form_helpers.md +54 -45
  49. data/guides/source/generators.md +20 -11
  50. data/guides/source/getting_started.md +330 -191
  51. data/guides/source/i18n.md +92 -62
  52. data/guides/source/index.html.erb +1 -0
  53. data/guides/source/initialization.md +108 -59
  54. data/guides/source/layout.html.erb +1 -4
  55. data/guides/source/layouts_and_rendering.md +24 -23
  56. data/guides/source/nested_model_forms.md +3 -3
  57. data/guides/source/plugins.md +26 -26
  58. data/guides/source/rails_application_templates.md +21 -3
  59. data/guides/source/rails_on_rack.md +1 -1
  60. data/guides/source/routing.md +97 -71
  61. data/guides/source/ruby_on_rails_guides_guidelines.md +10 -12
  62. data/guides/source/security.md +39 -33
  63. data/guides/source/testing.md +111 -108
  64. data/guides/source/upgrading_ruby_on_rails.md +131 -14
  65. data/guides/source/working_with_javascript_in_rails.md +18 -16
  66. data/guides/w3c_validator.rb +2 -0
  67. metadata +37 -94
  68. data/guides/bug_report_templates/generic_gem.rb +0 -15
  69. data/guides/bug_report_templates/generic_master.rb +0 -26
  70. data/guides/code/getting_started/Gemfile +0 -40
  71. data/guides/code/getting_started/Gemfile.lock +0 -125
  72. data/guides/code/getting_started/README.rdoc +0 -28
  73. data/guides/code/getting_started/Rakefile +0 -6
  74. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  75. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  76. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  77. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  78. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  79. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  80. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  81. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  82. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  83. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  84. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  85. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  86. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  87. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  88. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  89. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  90. data/guides/code/getting_started/app/models/comment.rb +0 -3
  91. data/guides/code/getting_started/app/models/post.rb +0 -7
  92. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  93. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  94. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  95. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  96. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  97. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  98. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  99. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  100. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  101. data/guides/code/getting_started/bin/bundle +0 -4
  102. data/guides/code/getting_started/bin/rails +0 -4
  103. data/guides/code/getting_started/bin/rake +0 -4
  104. data/guides/code/getting_started/config.ru +0 -4
  105. data/guides/code/getting_started/config/application.rb +0 -18
  106. data/guides/code/getting_started/config/boot.rb +0 -4
  107. data/guides/code/getting_started/config/database.yml +0 -25
  108. data/guides/code/getting_started/config/environment.rb +0 -5
  109. data/guides/code/getting_started/config/environments/development.rb +0 -30
  110. data/guides/code/getting_started/config/environments/production.rb +0 -80
  111. data/guides/code/getting_started/config/environments/test.rb +0 -36
  112. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  113. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  114. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  115. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  116. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  117. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  118. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  119. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  120. data/guides/code/getting_started/config/locales/en.yml +0 -23
  121. data/guides/code/getting_started/config/routes.rb +0 -7
  122. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  123. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  124. data/guides/code/getting_started/db/schema.rb +0 -33
  125. data/guides/code/getting_started/db/seeds.rb +0 -7
  126. data/guides/code/getting_started/public/404.html +0 -60
  127. data/guides/code/getting_started/public/422.html +0 -60
  128. data/guides/code/getting_started/public/500.html +0 -59
  129. data/guides/code/getting_started/public/favicon.ico +0 -0
  130. data/guides/code/getting_started/public/robots.txt +0 -5
  131. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  132. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  133. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  134. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  135. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  136. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  137. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  138. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  139. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  140. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  141. data/guides/code/getting_started/test/test_helper.rb +0 -12
@@ -24,9 +24,9 @@ NOTE: Bugs in the most recent released version of Ruby on Rails are likely to ge
24
24
 
25
25
  ### Creating a Bug Report
26
26
 
27
- If you've found a problem in Ruby on Rails which is not a security risk, do a search in GitHub under [Issues](https://github.com/rails/rails/issues) in case it was already reported. If you find no issue addressing it you can [add a new one](https://github.com/rails/rails/issues/new). (See the next section for reporting security issues.)
27
+ If you've found a problem in Ruby on Rails which is not a security risk, do a search in GitHub under [Issues](https://github.com/rails/rails/issues) in case it has already been reported. If you do not find any issue addressing it you may proceed to [open a new one](https://github.com/rails/rails/issues/new). (See the next section for reporting security issues.)
28
28
 
29
- At the minimum, your issue report needs a title and descriptive text. But that's only a minimum. You should include as much relevant information as possible. You need at least to post the code sample that has the issue. Even better is to include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself - and others - to replicate the bug and figure out a fix.
29
+ Your issue report should contain a title and a clear description of the issue at the bare minimum. You should include as much relevant information as possible and should at least post a code sample that demonstrates the issue. It would be even better if you could include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself - and others - to replicate the bug and figure out a fix.
30
30
 
31
31
  Then, don't get your hopes up! Unless you have a "Code Red, Mission Critical, the World is Coming to an End" kind of bug, you're creating this issue report in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the issue report will automatically see any activity or that others will jump to fix it. Creating an issue like this is mostly to help yourself start on the path of fixing the problem and for others to confirm it with an "I'm having this problem too" comment.
32
32
 
@@ -50,7 +50,7 @@ Please don't put "feature request" items into GitHub Issues. If there's a new
50
50
  feature that you want to see added to Ruby on Rails, you'll need to write the
51
51
  code yourself - or convince someone else to partner with you to write the code.
52
52
  Later in this guide you'll find detailed instructions for proposing a patch to
53
- Ruby on Rails. If you enter a wishlist item in GitHub Issues with no code, you
53
+ Ruby on Rails. If you enter a wish list item in GitHub Issues with no code, you
54
54
  can expect it to be marked "invalid" as soon as it's reviewed.
55
55
 
56
56
  Sometimes, the line between 'bug' and 'feature' is a hard one to draw.
@@ -69,89 +69,6 @@ won't be accepted." But it's the proper place to discuss new ideas. GitHub
69
69
  Issues are not a particularly good venue for the sometimes long and involved
70
70
  discussions new features require.
71
71
 
72
- Setting Up a Development Environment
73
- ------------------------------------
74
-
75
- To move on from submitting bugs to helping resolve existing issues or contributing your own code to Ruby on Rails, you _must_ be able to run its test suite. In this section of the guide you'll learn how to set up the tests on your own computer.
76
-
77
- ### The Easy Way
78
-
79
- The easiest and recommended way to get a development environment ready to hack is to use the [Rails development box](https://github.com/rails/rails-dev-box).
80
-
81
- ### The Hard Way
82
-
83
- In case you can't use the Rails development box, see section above, check [this other guide](development_dependencies_install.html).
84
-
85
-
86
- Running an Application Against Your Local Branch
87
- ------------------------------------------------
88
-
89
- The `--dev` flag of `rails new` generates an application that uses your local
90
- branch:
91
-
92
- ```bash
93
- $ cd rails
94
- $ bundle exec rails new ~/my-test-app --dev
95
- ```
96
-
97
- The application generated in `~/my-test-app` runs against your local branch
98
- and in particular sees any modifications upon server reboot.
99
-
100
-
101
- Testing Active Record
102
- ---------------------
103
-
104
- This is how you run the Active Record test suite only for SQLite3:
105
-
106
- ```bash
107
- $ cd activerecord
108
- $ bundle exec rake test_sqlite3
109
- ```
110
-
111
- You can now run the tests as you did for `sqlite3`. The tasks are respectively
112
-
113
- ```bash
114
- test_mysql
115
- test_mysql2
116
- test_postgresql
117
- ```
118
-
119
- Finally,
120
-
121
- ```bash
122
- $ bundle exec rake test
123
- ```
124
-
125
- will now run the four of them in turn.
126
-
127
- You can also run any single test separately:
128
-
129
- ```bash
130
- $ ARCONN=sqlite3 ruby -Itest test/cases/associations/has_many_associations_test.rb
131
- ```
132
-
133
- You can invoke `test_jdbcmysql`, `test_jdbcsqlite3` or `test_jdbcpostgresql` also. See the file `activerecord/RUNNING_UNIT_TESTS.rdoc` for information on running more targeted database tests, or the file `ci/travis.rb` for the test suite run by the continuous integration server.
134
-
135
- ### Warnings
136
-
137
- The test suite runs with warnings enabled. Ideally, Ruby on Rails should issue no warnings, but there may be a few, as well as some from third-party libraries. Please ignore (or fix!) them, if any, and submit patches that do not issue new warnings.
138
-
139
- If you are sure about what you are doing and would like to have a more clear output, there's a way to override the flag:
140
-
141
- ```bash
142
- $ RUBYOPT=-W0 bundle exec rake test
143
- ```
144
-
145
- ### Older Versions of Ruby on Rails
146
-
147
- If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 3-0-stable branch:
148
-
149
- ```bash
150
- $ git branch --track 3-0-stable origin/3-0-stable
151
- $ git checkout 3-0-stable
152
- ```
153
-
154
- TIP: You may want to [put your Git branch name in your shell prompt](http://qugstart.com/blog/git-and-svn/add-colored-git-branch-name-to-your-shell-prompt/) to make it easier to remember which version of the code you're working with.
155
72
 
156
73
  Helping to Resolve Existing Issues
157
74
  ----------------------------------
@@ -192,9 +109,7 @@ After applying their branch, test it out! Here are some things to think about:
192
109
 
193
110
  Once you're happy that the pull request contains a good change, comment on the GitHub issue indicating your approval. Your comment should indicate that you like the change and what you like about it. Something like:
194
111
 
195
- <blockquote>
196
- I like the way you've restructured that code in generate_finder_sql - much nicer. The tests look good too.
197
- </blockquote>
112
+ >I like the way you've restructured that code in generate_finder_sql - much nicer. The tests look good too.
198
113
 
199
114
  If your comment simply says "+1", then odds are that other reviewers aren't going to take it too seriously. Show that you took the time to review the pull request.
200
115
 
@@ -227,9 +142,21 @@ WARNING: Docrails has a very strict policy: no code can be touched whatsoever, n
227
142
  Contributing to the Rails Code
228
143
  ------------------------------
229
144
 
145
+ ### Setting Up a Development Environment
146
+
147
+ To move on from submitting bugs to helping resolve existing issues or contributing your own code to Ruby on Rails, you _must_ be able to run its test suite. In this section of the guide you'll learn how to setup the tests on your own computer.
148
+
149
+ #### The Easy Way
150
+
151
+ The easiest and recommended way to get a development environment ready to hack is to use the [Rails development box](https://github.com/rails/rails-dev-box).
152
+
153
+ #### The Hard Way
154
+
155
+ In case you can't use the Rails development box, see [this other guide](development_dependencies_install.html).
156
+
230
157
  ### Clone the Rails Repository
231
158
 
232
- The first thing you need to do to be able to contribute code is to clone the repository:
159
+ To be able to contribute code, you need to clone the Rails repository:
233
160
 
234
161
  ```bash
235
162
  $ git clone git://github.com/rails/rails.git
@@ -244,29 +171,31 @@ $ git checkout -b my_new_branch
244
171
 
245
172
  It doesn't matter much what name you use, because this branch will only exist on your local computer and your personal repository on GitHub. It won't be part of the Rails Git repository.
246
173
 
174
+ ### Running an Application Against Your Local Branch
175
+
176
+ In case you need a dummy Rails app to test changes, the `--dev` flag of `rails new` generates an application that uses your local branch:
177
+
178
+ ```bash
179
+ $ cd rails
180
+ $ bundle exec rails new ~/my-test-app --dev
181
+ ```
182
+
183
+ The application generated in `~/my-test-app` runs against your local branch
184
+ and in particular sees any modifications upon server reboot.
185
+
247
186
  ### Write Your Code
248
187
 
249
- Now get busy and add or edit code. You're on your branch now, so you can write whatever you want (you can check to make sure you're on the right branch with `git branch -a`). But if you're planning to submit your change back for inclusion in Rails, keep a few things in mind:
188
+ Now get busy and add/edit code. You're on your branch now, so you can write whatever you want (make sure you're on the right branch with `git branch -a`). But if you're planning to submit your change back for inclusion in Rails, keep a few things in mind:
250
189
 
251
190
  * Get the code right.
252
191
  * Use Rails idioms and helpers.
253
192
  * Include tests that fail without your code, and pass with it.
254
193
  * Update the (surrounding) documentation, examples elsewhere, and the guides: whatever is affected by your contribution.
255
194
 
256
- It is not customary in Rails to run the full test suite before pushing
257
- changes. The railties test suite in particular takes a long time, and even
258
- more if the source code is mounted in `/vagrant` as happens in the recommended
259
- workflow with the [rails-dev-box](https://github.com/rails/rails-dev-box).
260
-
261
- As a compromise, test what your code obviously affects, and if the change is
262
- not in railties, run the whole test suite of the affected component. If all
263
- tests are passing, that's enough to propose your contribution. We have
264
- [Travis CI](https://travis-ci.org/rails/rails) as a safety net for catching
265
- unexpected breakages elsewhere.
266
195
 
267
196
  TIP: Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability of Rails will generally not be accepted.
268
197
 
269
- ### Follow the Coding Conventions
198
+ #### Follow the Coding Conventions
270
199
 
271
200
  Rails follows a simple set of coding style conventions:
272
201
 
@@ -284,13 +213,136 @@ Rails follows a simple set of coding style conventions:
284
213
 
285
214
  The above are guidelines - please use your best judgment in using them.
286
215
 
216
+ ### Benchmark Your Code
217
+
218
+ If your change has an impact on the performance of Rails, please use the
219
+ [benchmark-ips](https://github.com/evanphx/benchmark-ips) gem to provide
220
+ benchmark results for comparison.
221
+
222
+ Here's an example of using benchmark-ips:
223
+
224
+ ```ruby
225
+ require 'benchmark/ips'
226
+
227
+ Benchmark.ips do |x|
228
+ x.report('addition') { 1 + 2 }
229
+ x.report('addition with send') { 1.send(:+, 2) }
230
+ end
231
+ ```
232
+
233
+ This will generate a report with the following information:
234
+
235
+ ```
236
+ Calculating -------------------------------------
237
+ addition 69114 i/100ms
238
+ addition with send 64062 i/100ms
239
+ -------------------------------------------------
240
+ addition 5307644.4 (±3.5%) i/s - 26539776 in 5.007219s
241
+ addition with send 3702897.9 (±3.5%) i/s - 18513918 in 5.006723s
242
+ ```
243
+
244
+ Please see the benchmark/ips [README](https://github.com/evanphx/benchmark-ips/blob/master/README.md) for more information.
245
+
246
+ ### Running Tests
247
+
248
+ It is not customary in Rails to run the full test suite before pushing
249
+ changes. The railties test suite in particular takes a long time, and even
250
+ more if the source code is mounted in `/vagrant` as happens in the recommended
251
+ workflow with the [rails-dev-box](https://github.com/rails/rails-dev-box).
252
+
253
+ As a compromise, test what your code obviously affects, and if the change is
254
+ not in railties, run the whole test suite of the affected component. If all
255
+ tests are passing, that's enough to propose your contribution. We have
256
+ [Travis CI](https://travis-ci.org/rails/rails) as a safety net for catching
257
+ unexpected breakages elsewhere.
258
+
259
+ #### Entire Rails:
260
+
261
+ To run all the tests, do:
262
+
263
+ ```bash
264
+ $ cd rails
265
+ $ bundle exec rake test
266
+ ```
267
+
268
+ #### For a Particular Component
269
+
270
+ You can run tests only for a particular component (e.g. Action Pack). For example,
271
+ to run Action Mailer tests:
272
+
273
+ ```bash
274
+ $ cd actionmailer
275
+ $ bundle exec rake test
276
+ ```
277
+
278
+ #### Running a Single Test
279
+
280
+ You can run a single test through ruby. For instance:
281
+
282
+ ```bash
283
+ $ cd actionmailer
284
+ $ ruby -w -Itest test/mail_layout_test.rb -n test_explicit_class_layout
285
+ ```
286
+
287
+ The `-n` option allows you to run a single method instead of the whole
288
+ file.
289
+
290
+ ##### Testing Active Record
291
+
292
+ This is how you run the Active Record test suite only for SQLite3:
293
+
294
+ ```bash
295
+ $ cd activerecord
296
+ $ bundle exec rake test:sqlite3
297
+ ```
298
+
299
+ You can now run the tests as you did for `sqlite3`. The tasks are respectively
300
+
301
+ ```bash
302
+ test:mysql
303
+ test:mysql2
304
+ test:postgresql
305
+ ```
306
+
307
+ Finally,
308
+
309
+ ```bash
310
+ $ bundle exec rake test
311
+ ```
312
+
313
+ will now run the four of them in turn.
314
+
315
+ You can also run any single test separately:
316
+
317
+ ```bash
318
+ $ ARCONN=sqlite3 ruby -Itest test/cases/associations/has_many_associations_test.rb
319
+ ```
320
+
321
+ To run a single test against all adapters, use:
322
+
323
+ ```bash
324
+ $ bundle exec rake TEST=test/cases/associations/has_many_associations_test.rb
325
+ ```
326
+
327
+ You can invoke `test_jdbcmysql`, `test_jdbcsqlite3` or `test_jdbcpostgresql` also. See the file `activerecord/RUNNING_UNIT_TESTS.rdoc` for information on running more targeted database tests, or the file `ci/travis.rb` for the test suite run by the continuous integration server.
328
+
329
+ ### Warnings
330
+
331
+ The test suite runs with warnings enabled. Ideally, Ruby on Rails should issue no warnings, but there may be a few, as well as some from third-party libraries. Please ignore (or fix!) them, if any, and submit patches that do not issue new warnings.
332
+
333
+ If you are sure about what you are doing and would like to have a more clear output, there's a way to override the flag:
334
+
335
+ ```bash
336
+ $ RUBYOPT=-W0 bundle exec rake test
337
+ ```
338
+
287
339
  ### Updating the CHANGELOG
288
340
 
289
341
  The CHANGELOG is an important part of every release. It keeps the list of changes for every Rails version.
290
342
 
291
343
  You should add an entry to the CHANGELOG of the framework that you modified if you're adding or removing a feature, committing a bug fix or adding deprecation notices. Refactorings and documentation changes generally should not go to the CHANGELOG.
292
344
 
293
- A CHANGELOG entry should summarize what was changed and should end with author's name and it should go on top of a CHANGELOG. You can use multiple lines if you need more space and you can attach code examples indented with 4 spaces. If a change is related to a specific issue, you should attach issue's number. Here is an example CHANGELOG entry:
345
+ A CHANGELOG entry should summarize what was changed and should end with author's name and it should go on top of a CHANGELOG. You can use multiple lines if you need more space and you can attach code examples indented with 4 spaces. If a change is related to a specific issue, you should attach the issue's number. Here is an example CHANGELOG entry:
294
346
 
295
347
  ```
296
348
  * Summary of a change that briefly describes what was changed. You can use multiple
@@ -314,9 +366,9 @@ Your name can be added directly after the last word if you don't provide any cod
314
366
  You should not be the only person who looks at the code before you submit it.
315
367
  If you know someone else who uses Rails, try asking them if they'll check out
316
368
  your work. If you don't know anyone else using Rails, try hopping into the IRC
317
- room or posting about your idea to the rails-core mailing list. Doing this in
318
- private before you push a patch out publicly is the smoke test for a patch:
319
- if you cant convince one other developer of the beauty of your code, you’re
369
+ room or posting about your idea to the rails-core mailing list. Doing this in
370
+ private before you push a patch out publicly is the "smoke test" for a patch:
371
+ if you can't convince one other developer of the beauty of your code, you’re
320
372
  unlikely to convince the core team either.
321
373
 
322
374
  ### Commit Your Changes
@@ -343,9 +395,9 @@ it should not be necessary to visit a webpage to check the history.
343
395
  Description can have multiple paragraphs and you can use code examples
344
396
  inside, just indent it with 4 spaces:
345
397
 
346
- class PostsController
398
+ class ArticlesController
347
399
  def index
348
- respond_with Post.limit(10)
400
+ render json: Article.limit(10)
349
401
  end
350
402
  end
351
403
 
@@ -467,11 +519,11 @@ the same way that you appreciate feedback on your patches.
467
519
 
468
520
  ### Iterate as Necessary
469
521
 
470
- It's entirely possible that the feedback you get will suggest changes. Don't get discouraged: the whole point of contributing to an active open source project is to tap into community knowledge. If people are encouraging you to tweak your code, then it's worth making the tweaks and resubmitting. If the feedback is that your code doesn't belong in the core, you might still think about releasing it as a gem.
522
+ It's entirely possible that the feedback you get will suggest changes. Don't get discouraged: the whole point of contributing to an active open source project is to tap into the knowledge of the community. If people are encouraging you to tweak your code, then it's worth making the tweaks and resubmitting. If the feedback is that your code doesn't belong in the core, you might still think about releasing it as a gem.
471
523
 
472
524
  #### Squashing commits
473
525
 
474
- One of the things that we may ask you to do is "squash your commits," which
526
+ One of the things that we may ask you to do is to "squash your commits", which
475
527
  will combine all of your commits into a single commit. We prefer pull requests
476
528
  that are a single commit. This makes it easier to backport changes to stable
477
529
  branches, squashing makes it easier to revert bad commits, and the git history
@@ -507,7 +559,18 @@ $ git push origin my_pull_request -f
507
559
  You should be able to refresh the pull request on GitHub and see that it has
508
560
  been updated.
509
561
 
510
- ### Backporting
562
+ ### Older Versions of Ruby on Rails
563
+
564
+ If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 4-0-stable branch:
565
+
566
+ ```bash
567
+ $ git branch --track 4-0-stable origin/4-0-stable
568
+ $ git checkout 4-0-stable
569
+ ```
570
+
571
+ TIP: You may want to [put your Git branch name in your shell prompt](http://qugstart.com/blog/git-and-svn/add-colored-git-branch-name-to-your-shell-prompt/) to make it easier to remember which version of the code you're working with.
572
+
573
+ #### Backporting
511
574
 
512
575
  Changes that are merged into master are intended for the next major release of Rails. Sometimes, it might be beneficial for your changes to propagate back to the maintenance releases for older stable branches. Generally, security fixes and bug fixes are good candidates for a backport, while new features and patches that introduce a change in behavior will not be accepted. When in doubt, it is best to consult a Rails team member before backporting your changes to avoid wasted effort.
513
576
 
@@ -64,7 +64,7 @@ Oscar Del Ben is a software engineer at <a href="http://www.wildfireapp.com/">Wi
64
64
  <% end %>
65
65
 
66
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>.
67
+ Pratik Naik is a Ruby on Rails developer at <a href="https://basecamp.com/">Basecamp</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
68
  <% end %>
69
69
 
70
70
  <%= author('Emilio Tagua', 'miloops') do %>
@@ -26,17 +26,17 @@ One common task is to inspect the contents of a variable. In Rails, you can do t
26
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
27
 
28
28
  ```html+erb
29
- <%= debug @post %>
29
+ <%= debug @article %>
30
30
  <p>
31
31
  <b>Title:</b>
32
- <%= @post.title %>
32
+ <%= @article.title %>
33
33
  </p>
34
34
  ```
35
35
 
36
36
  You'll see something like this:
37
37
 
38
38
  ```yaml
39
- --- !ruby/object:Post
39
+ --- !ruby/object Article
40
40
  attributes:
41
41
  updated_at: 2008-09-05 22:55:47
42
42
  body: It's a very helpful guide for debugging your Rails app.
@@ -55,10 +55,10 @@ Title: Rails debugging guide
55
55
  Displaying an instance variable, or any other object or method, in YAML format can be achieved this way:
56
56
 
57
57
  ```html+erb
58
- <%= simple_format @post.to_yaml %>
58
+ <%= simple_format @article.to_yaml %>
59
59
  <p>
60
60
  <b>Title:</b>
61
- <%= @post.title %>
61
+ <%= @article.title %>
62
62
  </p>
63
63
  ```
64
64
 
@@ -67,7 +67,7 @@ The `to_yaml` method converts the method to YAML format leaving it more readable
67
67
  As a result of this, you will have something like this in your view:
68
68
 
69
69
  ```yaml
70
- --- !ruby/object:Post
70
+ --- !ruby/object Article
71
71
  attributes:
72
72
  updated_at: 2008-09-05 22:55:47
73
73
  body: It's a very helpful guide for debugging your Rails app.
@@ -88,7 +88,7 @@ Another useful method for displaying object values is `inspect`, especially when
88
88
  <%= [1, 2, 3, 4, 5].inspect %>
89
89
  <p>
90
90
  <b>Title:</b>
91
- <%= @post.title %>
91
+ <%= @article.title %>
92
92
  </p>
93
93
  ```
94
94
 
@@ -123,7 +123,7 @@ config.logger = Logger.new(STDOUT)
123
123
  config.logger = Log4r::Logger.new("Application Log")
124
124
  ```
125
125
 
126
- TIP: By default, each log is created under `Rails.root/log/` and the log file name is `environment_name.log`.
126
+ TIP: By default, each log is created under `Rails.root/log/` and the log file is named after the environment in which the application is running.
127
127
 
128
128
  ### Log Levels
129
129
 
@@ -153,18 +153,18 @@ logger.fatal "Terminating application, raised unrecoverable error!!!"
153
153
  Here's an example of a method instrumented with extra logging:
154
154
 
155
155
  ```ruby
156
- class PostsController < ApplicationController
156
+ class ArticlesController < ApplicationController
157
157
  # ...
158
158
 
159
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)
160
+ @article = Article.new(params[:article])
161
+ logger.debug "New article: #{@article.attributes.inspect}"
162
+ logger.debug "Article should be valid: #{@article.valid?}"
163
+
164
+ if @article.save
165
+ flash[:notice] = 'Article was successfully created.'
166
+ logger.debug "The article was saved and now the user is going to be redirected..."
167
+ redirect_to(@article)
168
168
  else
169
169
  render action: "new"
170
170
  end
@@ -177,21 +177,21 @@ end
177
177
  Here's an example of the log generated when this controller action is executed:
178
178
 
179
179
  ```
180
- Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
180
+ Processing ArticlesController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
181
181
  Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl
182
182
  vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4
183
- Parameters: {"commit"=>"Create", "post"=>{"title"=>"Debugging Rails",
183
+ Parameters: {"commit"=>"Create", "article"=>{"title"=>"Debugging Rails",
184
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!!!",
185
+ "authenticity_token"=>"2059c1286e93402e389127b1153204e0d1e275dd", "action"=>"create", "controller"=>"articles"}
186
+ New article: {"updated_at"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!",
187
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",
188
+ Article should be valid: true
189
+ Article Create (0.000443) INSERT INTO "articles" ("updated_at", "title", "body", "published",
190
190
  "created_at") VALUES('2008-09-08 14:52:54', 'Debugging Rails',
191
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]
192
+ The article was saved and now the user is going to be redirected...
193
+ Redirected to # Article:0x20af760>
194
+ Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/articles]
195
195
  ```
196
196
 
197
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.
@@ -240,430 +240,560 @@ The contents of the block, and therefore the string interpolation, is only
240
240
  evaluated if debug is enabled. This performance savings is only really
241
241
  noticeable with large amounts of logging, but it's a good practice to employ.
242
242
 
243
- Debugging with the `debugger` gem
243
+ Debugging with the `byebug` gem
244
244
  ---------------------------------
245
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.
246
+ When your code is behaving in unexpected ways, you can try printing to logs or
247
+ the console to diagnose the problem. Unfortunately, there are times when this
248
+ sort of error tracking is not effective in finding the root cause of a problem.
249
+ When you actually need to journey into your running source code, the debugger
250
+ is your best companion.
247
251
 
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.
252
+ The debugger can also help you if you want to learn about the Rails source code
253
+ but don't know where to start. Just debug any request to your application and
254
+ use this guide to learn how to move from the code you have written deeper into
255
+ Rails code.
249
256
 
250
257
  ### Setup
251
258
 
252
- You can use the `debugger` gem to set breakpoints and step through live code in Rails. To install it, just run:
259
+ You can use the `byebug` gem to set breakpoints and step through live code in
260
+ Rails. To install it, just run:
253
261
 
254
262
  ```bash
255
- $ gem install debugger
263
+ $ gem install byebug
256
264
  ```
257
265
 
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.
266
+ Inside any Rails application you can then invoke the debugger by calling the
267
+ `byebug` method.
259
268
 
260
269
  Here's an example:
261
270
 
262
271
  ```ruby
263
272
  class PeopleController < ApplicationController
264
273
  def new
265
- debugger
274
+ byebug
266
275
  @person = Person.new
267
276
  end
268
277
  end
269
278
  ```
270
279
 
271
- If you see this message in the console or logs:
280
+ ### The Shell
281
+
282
+ As soon as your application calls the `byebug` method, the debugger will be
283
+ started in a debugger shell inside the terminal window where you launched your
284
+ application server, and you will be placed at the debugger's prompt `(byebug)`.
285
+ Before the prompt, the code around the line that is about to be run will be
286
+ displayed and the current line will be marked by '=>'. Like this:
272
287
 
273
288
  ```
274
- ***** Debugger requested, but was not available: Start server with --debugger to enable *****
289
+ [1, 10] in /PathTo/project/app/controllers/articles_controller.rb
290
+ 3:
291
+ 4: # GET /articles
292
+ 5: # GET /articles.json
293
+ 6: def index
294
+ 7: byebug
295
+ => 8: @articles = Article.find_recent
296
+ 9:
297
+ 10: respond_to do |format|
298
+ 11: format.html # index.html.erb
299
+ 12: format.json { render json: @articles }
300
+
301
+ (byebug)
275
302
  ```
276
303
 
277
- Make sure you have started your web server with the option `--debugger`:
304
+ If you got there by a browser request, the browser tab containing the request
305
+ will be hung until the debugger has finished and the trace has finished
306
+ processing the entire request.
307
+
308
+ For example:
278
309
 
279
310
  ```bash
280
- $ rails server --debugger
281
311
  => Booting WEBrick
282
- => Rails 4.1.4 application starting on http://0.0.0.0:3000
283
- => Debugger enabled
284
- ...
285
- ```
312
+ => Rails 4.2.0 application starting in development on http://0.0.0.0:3000
313
+ => Run `rails server -h` for more startup options
314
+ => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
315
+ => Ctrl-C to shutdown server
316
+ [2014-04-11 13:11:47] INFO WEBrick 1.3.1
317
+ [2014-04-11 13:11:47] INFO ruby 2.1.1 (2014-02-24) [i686-linux]
318
+ [2014-04-11 13:11:47] INFO WEBrick::HTTPServer#start: pid=6370 port=3000
286
319
 
287
- TIP: In development mode, you can dynamically `require 'debugger'` instead of restarting the server, even if it was started without `--debugger`.
288
320
 
289
- ### The Shell
321
+ Started GET "/" for 127.0.0.1 at 2014-04-11 13:11:48 +0200
322
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
323
+ Processing by ArticlesController#index as HTML
290
324
 
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.
325
+ [3, 12] in /PathTo/project/app/controllers/articles_controller.rb
326
+ 3:
327
+ 4: # GET /articles
328
+ 5: # GET /articles.json
329
+ 6: def index
330
+ 7: byebug
331
+ => 8: @articles = Article.find_recent
332
+ 9:
333
+ 10: respond_to do |format|
334
+ 11: format.html # index.html.erb
335
+ 12: format.json { render json: @articles }
292
336
 
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.
337
+ (byebug)
338
+ ```
294
339
 
295
- For example:
340
+ Now it's time to explore and dig into your application. A good place to start is
341
+ by asking the debugger for help. Type: `help`
296
342
 
297
- ```bash
298
- @posts = Post.all
299
- (rdb:7)
300
343
  ```
344
+ (byebug) help
301
345
 
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`
346
+ byebug 2.7.0
303
347
 
304
- ```
305
- (rdb:7) help
306
- ruby-debug help v0.10.2
307
348
  Type 'help <command-name>' for help on a specific command
308
349
 
309
350
  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
351
+ backtrace delete enable help list pry next restart source up
352
+ break disable eval info method ps save step var
353
+ catch display exit interrupt next putl set thread
354
+ condition down finish irb p quit show trace
355
+ continue edit frame kill pp reload skip undisplay
315
356
  ```
316
357
 
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.
358
+ TIP: To view the help menu for any command use `help <command-name>` at the
359
+ debugger prompt. For example: _`help list`_. You can abbreviate any debugging
360
+ command by supplying just enough letters to distinguish them from other
361
+ commands, so you can also use `l` for the `list` command, for example.
320
362
 
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 `=>`.
363
+ To see the previous ten lines you should type `list-` (or `l-`)
322
364
 
323
365
  ```
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
- ```
366
+ (byebug) l-
337
367
 
338
- If you repeat the `list` command, this time using just `l`, the next ten lines of the file will be printed out.
368
+ [1, 10] in /PathTo/project/app/controllers/articles_controller.rb
369
+ 1 class ArticlesController < ApplicationController
370
+ 2 before_action :set_article, only: [:show, :edit, :update, :destroy]
371
+ 3
372
+ 4 # GET /articles
373
+ 5 # GET /articles.json
374
+ 6 def index
375
+ 7 byebug
376
+ 8 @articles = Article.find_recent
377
+ 9
378
+ 10 respond_to do |format|
339
379
 
340
380
  ```
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
381
 
357
- On the other hand, to see the previous ten lines you should type `list-` (or `l-`)
382
+ This way you can move inside the file, being able to see the code above and over
383
+ the line where you added the `byebug` call. Finally, to see where you are in
384
+ the code again you can type `list=`
358
385
 
359
386
  ```
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
- ```
387
+ (byebug) list=
373
388
 
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=`
389
+ [3, 12] in /PathTo/project/app/controllers/articles_controller.rb
390
+ 3:
391
+ 4: # GET /articles
392
+ 5: # GET /articles.json
393
+ 6: def index
394
+ 7: byebug
395
+ => 8: @articles = Article.find_recent
396
+ 9:
397
+ 10: respond_to do |format|
398
+ 11: format.html # index.html.erb
399
+ 12: format.json { render json: @articles }
376
400
 
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 }
401
+ (byebug)
390
402
  ```
391
403
 
392
404
  ### The Context
393
405
 
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
406
+ When you start debugging your application, you will be placed in different
407
+ contexts as you go through the different parts of the stack.
408
+
409
+ The debugger creates a context when a stopping point or an event is reached. The
410
+ context has information about the suspended program which enables the debugger
411
+ to inspect the frame stack, evaluate variables from the perspective of the
412
+ debugged program, and contains information about the place where the debugged
413
+ program is stopped.
414
+
415
+ At any time you can call the `backtrace` command (or its alias `where`) to print
416
+ the backtrace of the application. This can be very helpful to know how you got
417
+ where you are. If you ever wondered about how you got somewhere in your code,
418
+ then `backtrace` will supply the answer.
419
+
420
+ ```
421
+ (byebug) where
422
+ --> #0 ArticlesController.index
423
+ at /PathTo/project/test_app/app/controllers/articles_controller.rb:8
424
+ #1 ActionController::ImplicitRender.send_action(method#String, *args#Array)
425
+ at /PathToGems/actionpack-4.2.0/lib/action_controller/metal/implicit_render.rb:4
426
+ #2 AbstractController::Base.process_action(action#NilClass, *args#Array)
427
+ at /PathToGems/actionpack-4.2.0/lib/abstract_controller/base.rb:189
428
+ #3 ActionController::Rendering.process_action(action#NilClass, *args#NilClass)
429
+ at /PathToGems/actionpack-4.2.0/lib/action_controller/metal/rendering.rb:10
410
430
  ...
411
431
  ```
412
432
 
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.
433
+ The current frame is marked with `-->`. You can move anywhere you want in this
434
+ trace (thus changing the context) by using the `frame _n_` command, where _n_ is
435
+ the specified frame number. If you do that, `byebug` will display your new
436
+ context.
414
437
 
415
438
  ```
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
439
+ (byebug) frame 2
440
+
441
+ [184, 193] in /PathToGems/actionpack-4.2.0/lib/abstract_controller/base.rb
442
+ 184: # is the intended way to override action dispatching.
443
+ 185: #
444
+ 186: # Notice that the first argument is the method to be dispatched
445
+ 187: # which is *not* necessarily the same as the action name.
446
+ 188: def process_action(method_name, *args)
447
+ => 189: send_action(method_name, *args)
448
+ 190: end
449
+ 191:
450
+ 192: # Actually call the method associated with the action. Override
451
+ 193: # this method if you wish to change how action methods are called,
452
+
453
+ (byebug)
419
454
  ```
420
455
 
421
- The available variables are the same as if you were running the code line by line. After all, that's what debugging is.
456
+ The available variables are the same as if you were running the code line by
457
+ line. After all, that's what debugging is.
422
458
 
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.
459
+ You can also use `up [n]` (`u` for abbreviated) and `down [n]` commands in order
460
+ to change the context _n_ frames up or down the stack respectively. _n_ defaults
461
+ to one. Up in this case is towards higher-numbered stack frames, and down is
462
+ towards lower-numbered stack frames.
424
463
 
425
464
  ### Threads
426
465
 
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:
466
+ The debugger can list, stop, resume and switch between running threads by using
467
+ the `thread` command (or the abbreviated `th`). This command has a handful of
468
+ options:
428
469
 
429
470
  * `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.
471
+ * `thread list` is used to list all threads and their statuses. The plus +
472
+ character and the number indicates the current thread of execution.
431
473
  * `thread stop _n_` stop thread _n_.
432
474
  * `thread resume _n_` resumes thread _n_.
433
475
  * `thread switch _n_` switches the current thread context to _n_.
434
476
 
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.
477
+ This command is very helpful, among other occasions, when you are debugging
478
+ concurrent threads and need to verify that there are no race conditions in your
479
+ code.
436
480
 
437
481
  ### Inspecting Variables
438
482
 
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|
483
+ Any expression can be evaluated in the current context. To evaluate an
484
+ expression, just type it!
485
+
486
+ This example shows how you can print the instance variables defined within the
487
+ current context:
488
+
489
+ ```
490
+ [3, 12] in /PathTo/project/app/controllers/articles_controller.rb
491
+ 3:
492
+ 4: # GET /articles
493
+ 5: # GET /articles.json
494
+ 6: def index
495
+ 7: byebug
496
+ => 8: @articles = Article.find_recent
497
+ 9:
498
+ 10: respond_to do |format|
499
+ 11: format.html # index.html.erb
500
+ 12: format.json { render json: @articles }
501
+
502
+ (byebug) instance_variables
503
+ [:@_action_has_layout, :@_routes, :@_headers, :@_status, :@_request,
504
+ :@_response, :@_env, :@_prefixes, :@_lookup_context, :@_action_name,
505
+ :@_response_body, :@marked_for_same_origin_verification, :@_config]
506
+ ```
507
+
508
+ As you may have figured out, all of the variables that you can access from a
509
+ controller are displayed. This list is dynamically updated as you execute code.
510
+ For example, run the next line using `next` (you'll learn more about this
511
+ command later in this guide).
512
+
513
+ ```
514
+ (byebug) next
515
+ [5, 14] in /PathTo/project/app/controllers/articles_controller.rb
516
+ 5 # GET /articles.json
517
+ 6 def index
518
+ 7 byebug
519
+ 8 @articles = Article.find_recent
520
+ 9
521
+ => 10 respond_to do |format|
522
+ 11 format.html # index.html.erb
523
+ 12 format.json { render json: @articles }
524
+ 13 end
525
+ 14 end
526
+ 15
527
+ (byebug)
458
528
  ```
459
529
 
460
530
  And then ask again for the instance_variables:
461
531
 
462
532
  ```
463
- (rdb:11) instance_variables.include? "@posts"
533
+ (byebug) instance_variables.include? "@articles"
464
534
  true
465
535
  ```
466
536
 
467
- Now `@posts` is included in the instance variables, because the line defining it was executed.
537
+ Now `@articles` is included in the instance variables, because the line defining it
538
+ was executed.
468
539
 
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.
540
+ TIP: You can also step into **irb** mode with the command `irb` (of course!).
541
+ This way an irb session will be started within the context you invoked it. But
542
+ be warned: this is an experimental feature.
470
543
 
471
- The `var` method is the most convenient way to show variables and their values:
544
+ The `var` method is the most convenient way to show variables and their values.
545
+ Let's let `byebug` to help us with it.
472
546
 
473
547
  ```
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
548
+ (byebug) help var
549
+ v[ar] cl[ass] show class variables of self
550
+ v[ar] const <object> show constants of object
551
+ v[ar] g[lobal] show global variables
552
+ v[ar] i[nstance] <object> show instance variables of object
553
+ v[ar] l[ocal] show local variables
479
554
  ```
480
555
 
481
- This is a great way to inspect the values of the current context variables. For example:
556
+ This is a great way to inspect the values of the current context variables. For
557
+ example, to check that we have no local variables currently defined.
482
558
 
483
559
  ```
484
- (rdb:9) var local
485
- __dbg_verbose_save => false
560
+ (byebug) var local
561
+ (byebug)
486
562
  ```
487
563
 
488
564
  You can also inspect for an object method this way:
489
565
 
490
566
  ```
491
- (rdb:9) var instance Post.new
492
- @attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"...
567
+ (byebug) var instance Article.new
568
+ @_start_transaction_state = {}
569
+ @aggregation_cache = {}
570
+ @association_cache = {}
571
+ @attributes = {"id"=>nil, "created_at"=>nil, "updated_at"=>nil}
493
572
  @attributes_cache = {}
494
- @new_record = true
573
+ @changed_attributes = nil
574
+ ...
495
575
  ```
496
576
 
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.
577
+ TIP: The commands `p` (print) and `pp` (pretty print) can be used to evaluate
578
+ Ruby expressions and display the value of variables to the console.
498
579
 
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.
580
+ You can use also `display` to start watching variables. This is a good way of
581
+ tracking the values of a variable while the execution goes on.
500
582
 
501
583
  ```
502
- (rdb:1) display @recent_comments
503
- 1: @recent_comments =
584
+ (byebug) display @articles
585
+ 1: @articles = nil
504
586
  ```
505
587
 
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).
588
+ The variables inside the displaying list will be printed with their values after
589
+ you move in the stack. To stop displaying a variable use `undisplay _n_` where
590
+ _n_ is the variable number (1 in the last example).
507
591
 
508
592
  ### Step by Step
509
593
 
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.
594
+ Now you should know where you are in the running trace and be able to print the
595
+ available variables. But lets continue and move on with the application
596
+ execution.
511
597
 
512
- Use `step` (abbreviated `s`) to continue running your program until the next logical stopping point and return control to the debugger.
598
+ Use `step` (abbreviated `s`) to continue running your program until the next
599
+ logical stopping point and return control to the debugger.
513
600
 
514
- TIP: You can also use `step+ n` and `step- n` to move forward or backward `n` steps respectively.
601
+ You may also use `next` which is similar to step, but function or method calls
602
+ that appear within the line of code are executed without stopping.
515
603
 
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.
604
+ TIP: You can also use `step n` or `next n` to move forwards `n` steps at once.
517
605
 
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.
606
+ The difference between `next` and `step` is that `step` stops at the next line
607
+ of code executed, doing just a single step, while `next` moves to the next line
608
+ without descending inside methods.
519
609
 
520
- For example, consider this block of code with an included `debugger` statement:
610
+ For example, consider the following situation:
521
611
 
522
612
  ```ruby
523
- class Author < ActiveRecord::Base
524
- has_one :editorial
525
- has_many :comments
613
+ Started GET "/" for 127.0.0.1 at 2014-04-11 13:39:23 +0200
614
+ Processing by ArticlesController#index as HTML
526
615
 
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
616
+ [1, 8] in /home/davidr/Proyectos/test_app/app/models/article.rb
617
+ 1: class Article < ActiveRecord::Base
618
+ 2:
619
+ 3: def self.find_recent(limit = 10)
620
+ 4: byebug
621
+ => 5: where('created_at > ?', 1.week.ago).limit(limit)
622
+ 6: end
623
+ 7:
624
+ 8: end
625
+
626
+ (byebug)
532
627
  ```
533
628
 
534
- TIP: You can use the debugger while using `rails console`. Just remember to `require "debugger"` before calling the `debugger` method.
629
+ If we use `next`, we want go deep inside method calls. Instead, byebug will go
630
+ to the next line within the same context. In this case, this is the last line of
631
+ the method, so `byebug` will jump to next next line of the previous frame.
535
632
 
536
633
  ```
537
- $ rails console
538
- Loading development environment (Rails 4.1.4)
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
- ```
634
+ (byebug) next
635
+ Next went up a frame because previous frame finished
547
636
 
548
- With the code stopped, take a look around:
637
+ [4, 13] in /PathTo/project/test_app/app/controllers/articles_controller.rb
638
+ 4: # GET /articles
639
+ 5: # GET /articles.json
640
+ 6: def index
641
+ 7: @articles = Article.find_recent
642
+ 8:
643
+ => 9: respond_to do |format|
644
+ 10: format.html # index.html.erb
645
+ 11: format.json { render json: @articles }
646
+ 12: end
647
+ 13: end
549
648
 
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
649
+ (byebug)
561
650
  ```
562
651
 
563
- You are at the end of the line, but... was this line executed? You can inspect the instance variables.
652
+ If we use `step` in the same situation, we will literally go the next ruby
653
+ instruction to be executed. In this case, the activesupport's `week` method.
564
654
 
565
655
  ```
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
- ```
656
+ (byebug) step
570
657
 
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:
658
+ [50, 59] in /PathToGems/activesupport-4.2.0/lib/active_support/core_ext/numeric/time.rb
659
+ 50: ActiveSupport::Duration.new(self * 24.hours, [[:days, self]])
660
+ 51: end
661
+ 52: alias :day :days
662
+ 53:
663
+ 54: def weeks
664
+ => 55: ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]])
665
+ 56: end
666
+ 57: alias :week :weeks
667
+ 58:
668
+ 59: def fortnights
572
669
 
670
+ (byebug)
573
671
  ```
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
672
 
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.
673
+ This is one of the best ways to find bugs in your code, or perhaps in Ruby on
674
+ Rails.
587
675
 
588
676
  ### Breakpoints
589
677
 
590
- A breakpoint makes your application stop whenever a certain point in the program is reached. The debugger shell is invoked in that line.
678
+ A breakpoint makes your application stop whenever a certain point in the program
679
+ is reached. The debugger shell is invoked in that line.
591
680
 
592
- You can add breakpoints dynamically with the command `break` (or just `b`). There are 3 possible ways of adding breakpoints manually:
681
+ You can add breakpoints dynamically with the command `break` (or just `b`).
682
+ There are 3 possible ways of adding breakpoints manually:
593
683
 
594
684
  * `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.
685
+ * `break file:line [if expression]`: set breakpoint in the _line_ number inside
686
+ the _file_. If an _expression_ is given it must evaluated to _true_ to fire up
687
+ the debugger.
688
+ * `break class(.|\#)method [if expression]`: set breakpoint in _method_ (. and
689
+ \# for class and instance method respectively) defined in _class_. The
690
+ _expression_ works the same way as with file:line.
691
+
692
+
693
+ For example, in the previous situation
597
694
 
598
695
  ```
599
- (rdb:5) break 10
600
- Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10
696
+ [4, 13] in /PathTo/project/app/controllers/articles_controller.rb
697
+ 4: # GET /articles
698
+ 5: # GET /articles.json
699
+ 6: def index
700
+ 7: @articles = Article.find_recent
701
+ 8:
702
+ => 9: respond_to do |format|
703
+ 10: format.html # index.html.erb
704
+ 11: format.json { render json: @articles }
705
+ 12: end
706
+ 13: end
707
+
708
+ (byebug) break 11
709
+ Created breakpoint 1 at /PathTo/project/app/controllers/articles_controller.rb:11
710
+
601
711
  ```
602
712
 
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.
713
+ Use `info breakpoints _n_` or `info break _n_` to list breakpoints. If you
714
+ supply a number, it lists that breakpoint. Otherwise it lists all breakpoints.
604
715
 
605
716
  ```
606
- (rdb:5) info breakpoints
717
+ (byebug) info breakpoints
607
718
  Num Enb What
608
- 1 y at filters.rb:10
719
+ 1 y at /PathTo/project/app/controllers/articles_controller.rb:11
609
720
  ```
610
721
 
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..
722
+ To delete breakpoints: use the command `delete _n_` to remove the breakpoint
723
+ number _n_. If no number is specified, it deletes all breakpoints that are
724
+ currently active.
612
725
 
613
726
  ```
614
- (rdb:5) delete 1
615
- (rdb:5) info breakpoints
727
+ (byebug) delete 1
728
+ (byebug) info breakpoints
616
729
  No breakpoints.
617
730
  ```
618
731
 
619
732
  You can also enable or disable breakpoints:
620
733
 
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.
734
+ * `enable breakpoints`: allow a _breakpoints_ list or all of them if no list is
735
+ specified, to stop your program. This is the default state when you create a
736
+ breakpoint.
622
737
  * `disable breakpoints`: the _breakpoints_ will have no effect on your program.
623
738
 
624
739
  ### Catching Exceptions
625
740
 
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.
741
+ The command `catch exception-name` (or just `cat exception-name`) can be used to
742
+ intercept an exception of type _exception-name_ when there would otherwise be no
743
+ handler for it.
627
744
 
628
745
  To list all active catchpoints use `catch`.
629
746
 
630
747
  ### Resuming Execution
631
748
 
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.
749
+ There are two ways to resume execution of an application that is stopped in the
750
+ debugger:
751
+
752
+ * `continue` [line-specification] \(or `c`): resume program execution, at the
753
+ address where your script last stopped; any breakpoints set at that address are
754
+ bypassed. The optional argument line-specification allows you to specify a line
755
+ number to set a one-time breakpoint which is deleted when that breakpoint is
756
+ reached.
757
+ * `finish` [frame-number] \(or `fin`): execute until the selected stack frame
758
+ returns. If no frame number is given, the application will run until the
759
+ currently selected frame returns. The currently selected frame starts out the
760
+ most-recent frame or 0 if no frame positioning (e.g up, down or frame) has been
761
+ performed. If a frame number is given it will run until the specified frame
762
+ returns.
636
763
 
637
764
  ### Editing
638
765
 
639
766
  Two commands allow you to open code from the debugger into an editor:
640
767
 
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.
768
+ * `edit [file:line]`: edit _file_ using the editor specified by the EDITOR
769
+ environment variable. A specific _line_ can also be given.
643
770
 
644
771
  ### Quitting
645
772
 
646
- To exit the debugger, use the `quit` command (abbreviated `q`), or its alias `exit`.
773
+ To exit the debugger, use the `quit` command (abbreviated `q`), or its alias
774
+ `exit`.
647
775
 
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.
776
+ A simple quit tries to terminate all threads in effect. Therefore your server
777
+ will be stopped and you will have to start it again.
649
778
 
650
779
  ### Settings
651
780
 
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
781
+ `byebug` has a few available options to tweak its behaviour:
658
782
 
659
- You can see the full list by using `help set`. Use `help set _subcommand_` to learn about a particular `set` command.
783
+ * `set autoreload`: Reload source code when changed (default: true).
784
+ * `set autolist`: Execute `list` command on every breakpoint (default: true).
785
+ * `set listsize _n_`: Set number of source lines to list by default to _n_
786
+ (default: 10)
787
+ * `set forcestep`: Make sure the `next` and `step` commands always move to a new
788
+ line.
660
789
 
661
- TIP: You can save these settings in an `.rdebugrc` file in your home directory. The debugger reads these global settings when it starts.
790
+ You can see the full list by using `help set`. Use `help set _subcommand_` to
791
+ learn about a particular `set` command.
662
792
 
663
- Here's a good start for an `.rdebugrc`:
793
+ TIP: You can save these settings in an `.byebugrc` file in your home directory.
794
+ The debugger reads these global settings when it starts. For example:
664
795
 
665
796
  ```bash
666
- set autolist
667
797
  set forcestep
668
798
  set listsize 25
669
799
  ```
@@ -671,35 +801,59 @@ set listsize 25
671
801
  Debugging Memory Leaks
672
802
  ----------------------
673
803
 
674
- A Ruby application (on Rails or not), can leak memory - either in the Ruby code or at the C code level.
804
+ A Ruby application (on Rails or not), can leak memory - either in the Ruby code
805
+ or at the C code level.
675
806
 
676
- In this section, you will learn how to find and fix such leaks by using tool such as Valgrind.
807
+ In this section, you will learn how to find and fix such leaks by using tool
808
+ such as Valgrind.
677
809
 
678
810
  ### Valgrind
679
811
 
680
- [Valgrind](http://valgrind.org/) is a Linux-only application for detecting C-based memory leaks and race conditions.
812
+ [Valgrind](http://valgrind.org/) is a Linux-only application for detecting
813
+ C-based memory leaks and race conditions.
681
814
 
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.
815
+ There are Valgrind tools that can automatically detect many memory management
816
+ and threading bugs, and profile your programs in detail. For example, if a C
817
+ extension in the interpreter calls `malloc()` but doesn't properly call
818
+ `free()`, this memory won't be available until the app terminates.
683
819
 
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.
820
+ For further information on how to install Valgrind and use with Ruby, refer to
821
+ [Valgrind and Ruby](http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/)
822
+ by Evan Weaver.
685
823
 
686
824
  Plugins for Debugging
687
825
  ---------------------
688
826
 
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.
827
+ There are some Rails plugins to help you to find errors and debug your
828
+ application. Here is a list of useful plugins for debugging:
829
+
830
+ * [Footnotes](https://github.com/josevalim/rails-footnotes) Every Rails page has
831
+ footnotes that give request information and link back to your source via
832
+ TextMate.
833
+ * [Query Trace](https://github.com/ntalbott/query_trace/tree/master) Adds query
834
+ origin tracing to your logs.
835
+ * [Query Reviewer](https://github.com/nesquena/query_reviewer) This rails plugin
836
+ not only runs "EXPLAIN" before each of your select queries in development, but
837
+ provides a small DIV in the rendered output of each page with the summary of
838
+ warnings for each query that it analyzed.
839
+ * [Exception Notifier](https://github.com/smartinez87/exception_notification/tree/master)
840
+ Provides a mailer object and a default set of templates for sending email
841
+ notifications when errors occur in a Rails application.
842
+ * [Better Errors](https://github.com/charliesome/better_errors) Replaces the
843
+ standard Rails error page with a new one containing more contextual information,
844
+ like source code and variable inspection.
845
+ * [RailsPanel](https://github.com/dejan/rails_panel) Chrome extension for Rails
846
+ development that will end your tailing of development.log. Have all information
847
+ about your Rails app requests in the browser - in the Developer Tools panel.
848
+ Provides insight to db/rendering/total times, parameter list, rendered views and
849
+ more.
697
850
 
698
851
  References
699
852
  ----------
700
853
 
701
854
  * [ruby-debug Homepage](http://bashdb.sourceforge.net/ruby-debug/home-page.html)
702
855
  * [debugger Homepage](https://github.com/cldwalker/debugger)
856
+ * [byebug Homepage](https://github.com/deivid-rodriguez/byebug)
703
857
  * [Article: Debugging a Rails application with ruby-debug](http://www.sitepoint.com/debug-rails-app-ruby-debug/)
704
858
  * [Ryan Bates' debugging ruby (revised) screencast](http://railscasts.com/episodes/54-debugging-ruby-revised)
705
859
  * [Ryan Bates' stack trace screencast](http://railscasts.com/episodes/24-the-stack-trace)