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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/guides/CHANGELOG.md +13 -102
- data/guides/Rakefile +2 -2
- data/guides/assets/javascripts/guides.js +6 -0
- data/guides/assets/stylesheets/main.css +4 -1
- data/guides/bug_report_templates/action_controller_gem.rb +2 -2
- data/guides/bug_report_templates/action_controller_master.rb +5 -2
- data/guides/bug_report_templates/active_record_master.rb +2 -0
- data/guides/rails_guides.rb +2 -2
- data/guides/rails_guides/helpers.rb +1 -1
- data/guides/rails_guides/levenshtein.rb +29 -21
- data/guides/rails_guides/markdown.rb +6 -7
- data/guides/rails_guides/markdown/renderer.rb +1 -1
- data/guides/source/2_3_release_notes.md +3 -3
- data/guides/source/3_0_release_notes.md +4 -4
- data/guides/source/3_1_release_notes.md +2 -2
- data/guides/source/3_2_release_notes.md +2 -2
- data/guides/source/4_1_release_notes.md +8 -9
- data/guides/source/4_2_release_notes.md +572 -0
- data/guides/source/_license.html.erb +1 -1
- data/guides/source/_welcome.html.erb +2 -8
- data/guides/source/action_controller_overview.md +79 -7
- data/guides/source/action_mailer_basics.md +36 -11
- data/guides/source/action_view_overview.md +138 -119
- data/guides/source/active_job_basics.md +253 -0
- data/guides/source/active_model_basics.md +23 -0
- data/guides/source/active_record_basics.md +16 -15
- data/guides/source/active_record_callbacks.md +12 -9
- data/guides/source/{migrations.md → active_record_migrations.md} +90 -217
- data/guides/source/active_record_postgresql.md +437 -0
- data/guides/source/active_record_querying.md +261 -261
- data/guides/source/active_record_validations.md +7 -7
- data/guides/source/active_support_core_extensions.md +105 -44
- data/guides/source/active_support_instrumentation.md +3 -2
- data/guides/source/api_documentation_guidelines.md +62 -16
- data/guides/source/asset_pipeline.md +58 -46
- data/guides/source/association_basics.md +47 -38
- data/guides/source/caching_with_rails.md +31 -6
- data/guides/source/command_line.md +56 -25
- data/guides/source/configuring.md +98 -19
- data/guides/source/contributing_to_ruby_on_rails.md +174 -111
- data/guides/source/credits.html.erb +1 -1
- data/guides/source/debugging_rails_applications.md +438 -284
- data/guides/source/development_dependencies_install.md +17 -4
- data/guides/source/documents.yaml +11 -7
- data/guides/source/engines.md +192 -203
- data/guides/source/form_helpers.md +54 -45
- data/guides/source/generators.md +20 -11
- data/guides/source/getting_started.md +330 -191
- data/guides/source/i18n.md +92 -62
- data/guides/source/index.html.erb +1 -0
- data/guides/source/initialization.md +108 -59
- data/guides/source/layout.html.erb +1 -4
- data/guides/source/layouts_and_rendering.md +24 -23
- data/guides/source/nested_model_forms.md +3 -3
- data/guides/source/plugins.md +26 -26
- data/guides/source/rails_application_templates.md +21 -3
- data/guides/source/rails_on_rack.md +1 -1
- data/guides/source/routing.md +97 -71
- data/guides/source/ruby_on_rails_guides_guidelines.md +10 -12
- data/guides/source/security.md +39 -33
- data/guides/source/testing.md +111 -108
- data/guides/source/upgrading_ruby_on_rails.md +131 -14
- data/guides/source/working_with_javascript_in_rails.md +18 -16
- data/guides/w3c_validator.rb +2 -0
- metadata +37 -94
- data/guides/bug_report_templates/generic_gem.rb +0 -15
- data/guides/bug_report_templates/generic_master.rb +0 -26
- data/guides/code/getting_started/Gemfile +0 -40
- data/guides/code/getting_started/Gemfile.lock +0 -125
- data/guides/code/getting_started/README.rdoc +0 -28
- data/guides/code/getting_started/Rakefile +0 -6
- data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
- data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
- data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
- data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
- data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
- data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
- data/guides/code/getting_started/app/models/comment.rb +0 -3
- data/guides/code/getting_started/app/models/post.rb +0 -7
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
- data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
- data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
- data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
- data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
- data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
- data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
- data/guides/code/getting_started/bin/bundle +0 -4
- data/guides/code/getting_started/bin/rails +0 -4
- data/guides/code/getting_started/bin/rake +0 -4
- data/guides/code/getting_started/config.ru +0 -4
- data/guides/code/getting_started/config/application.rb +0 -18
- data/guides/code/getting_started/config/boot.rb +0 -4
- data/guides/code/getting_started/config/database.yml +0 -25
- data/guides/code/getting_started/config/environment.rb +0 -5
- data/guides/code/getting_started/config/environments/development.rb +0 -30
- data/guides/code/getting_started/config/environments/production.rb +0 -80
- data/guides/code/getting_started/config/environments/test.rb +0 -36
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
- data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
- data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
- data/guides/code/getting_started/config/initializers/locale.rb +0 -9
- data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
- data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
- data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
- data/guides/code/getting_started/config/locales/en.yml +0 -23
- data/guides/code/getting_started/config/routes.rb +0 -7
- data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
- data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
- data/guides/code/getting_started/db/schema.rb +0 -33
- data/guides/code/getting_started/db/seeds.rb +0 -7
- data/guides/code/getting_started/public/404.html +0 -60
- data/guides/code/getting_started/public/422.html +0 -60
- data/guides/code/getting_started/public/500.html +0 -59
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +0 -5
- data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
- data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
- data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
- data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
- data/guides/code/getting_started/test/models/comment_test.rb +0 -7
- data/guides/code/getting_started/test/models/post_test.rb +0 -7
- 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
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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.
|
318
|
-
private before you push a patch out publicly is the
|
319
|
-
if you can
|
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
|
398
|
+
class ArticlesController
|
347
399
|
def index
|
348
|
-
|
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
|
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,
|
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
|
-
###
|
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="
|
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 => :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 @
|
29
|
+
<%= debug @article %>
|
30
30
|
<p>
|
31
31
|
<b>Title:</b>
|
32
|
-
<%= @
|
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
|
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 @
|
58
|
+
<%= simple_format @article.to_yaml %>
|
59
59
|
<p>
|
60
60
|
<b>Title:</b>
|
61
|
-
<%= @
|
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
|
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
|
-
<%= @
|
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
|
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
|
156
|
+
class ArticlesController < ApplicationController
|
157
157
|
# ...
|
158
158
|
|
159
159
|
def create
|
160
|
-
@
|
161
|
-
logger.debug "New
|
162
|
-
logger.debug "
|
163
|
-
|
164
|
-
if @
|
165
|
-
flash[:notice] =
|
166
|
-
logger.debug "The
|
167
|
-
redirect_to(@
|
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
|
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", "
|
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"=>"
|
186
|
-
New
|
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
|
-
|
189
|
-
|
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
|
193
|
-
Redirected to
|
194
|
-
Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/
|
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 `
|
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
|
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
|
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 `
|
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
|
263
|
+
$ gem install byebug
|
256
264
|
```
|
257
265
|
|
258
|
-
|
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
|
-
|
274
|
+
byebug
|
266
275
|
@person = Person.new
|
267
276
|
end
|
268
277
|
end
|
269
278
|
```
|
270
279
|
|
271
|
-
|
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
|
-
|
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
|
-
|
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.
|
283
|
-
=>
|
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
|
-
|
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
|
-
|
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
|
-
|
337
|
+
(byebug)
|
338
|
+
```
|
294
339
|
|
295
|
-
|
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
|
-
|
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
|
311
|
-
break disable eval info
|
312
|
-
catch display exit
|
313
|
-
condition down finish
|
314
|
-
continue edit frame
|
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
|
318
|
-
|
319
|
-
|
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
|
-
|
363
|
+
To see the previous ten lines you should type `list-` (or `l-`)
|
322
364
|
|
323
365
|
```
|
324
|
-
(
|
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
|
-
|
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
|
-
|
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
|
-
(
|
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
|
-
|
375
|
-
|
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
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
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
|
-
|
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
|
-
(
|
417
|
-
|
418
|
-
|
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
|
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
|
-
|
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
|
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 +
|
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
|
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
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
[
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
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
|
-
(
|
533
|
+
(byebug) instance_variables.include? "@articles"
|
464
534
|
true
|
465
535
|
```
|
466
536
|
|
467
|
-
Now `@
|
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!).
|
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
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
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
|
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
|
-
(
|
485
|
-
|
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
|
-
(
|
492
|
-
@
|
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
|
-
@
|
573
|
+
@changed_attributes = nil
|
574
|
+
...
|
495
575
|
```
|
496
576
|
|
497
|
-
TIP: The commands `p` (print) and `pp` (pretty print) can be used to evaluate
|
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
|
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
|
-
(
|
503
|
-
1: @
|
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
|
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
|
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
|
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
|
-
|
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
|
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
|
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
|
610
|
+
For example, consider the following situation:
|
521
611
|
|
522
612
|
```ruby
|
523
|
-
|
524
|
-
|
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
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
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
|
-
|
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
|
-
|
538
|
-
|
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
|
-
|
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
|
-
|
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
|
-
(
|
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
|
-
|
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
|
-
|
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
|
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`).
|
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
|
596
|
-
|
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
|
-
|
600
|
-
|
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
|
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
|
-
(
|
717
|
+
(byebug) info breakpoints
|
607
718
|
Num Enb What
|
608
|
-
|
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
|
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
|
-
(
|
615
|
-
(
|
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
|
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
|
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
|
633
|
-
|
634
|
-
|
635
|
-
* `
|
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
|
642
|
-
|
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
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
690
|
-
|
691
|
-
|
692
|
-
* [
|
693
|
-
|
694
|
-
|
695
|
-
* [
|
696
|
-
|
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)
|