railties 3.1.1 → 3.1.2.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +2382 -0
- data/guides/output/2_2_release_notes.html +565 -0
- data/guides/output/2_3_release_notes.html +713 -0
- data/guides/output/3_0_release_notes.html +652 -0
- data/guides/output/3_1_release_notes.html +670 -0
- data/guides/output/action_controller_overview.html +925 -0
- data/guides/output/action_mailer_basics.html +658 -0
- data/guides/output/action_view_overview.html +1471 -0
- data/guides/output/active_model_basics.html +349 -0
- data/guides/output/active_record_basics.html +364 -0
- data/guides/output/active_record_querying.html +1272 -0
- data/guides/output/active_record_validations_callbacks.html +1292 -0
- data/guides/output/active_resource_basics.html +252 -0
- data/guides/output/active_support_core_extensions.html +3374 -0
- data/guides/output/ajax_on_rails.html +412 -0
- data/guides/output/api_documentation_guidelines.html +317 -0
- data/guides/output/asset_pipeline.html +691 -0
- data/guides/output/association_basics.html +1742 -0
- data/guides/output/caching_with_rails.html +533 -0
- data/guides/output/command_line.html +662 -0
- data/guides/output/configuring.html +811 -0
- data/guides/output/contribute.html +216 -0
- data/guides/output/contributing_to_ruby_on_rails.html +465 -0
- data/guides/output/credits.html +210 -0
- data/guides/output/debugging_rails_applications.html +791 -0
- data/guides/output/engines.html +673 -0
- data/guides/output/form_helpers.html +850 -0
- data/guides/output/generators.html +725 -0
- data/guides/output/getting_started.html +1980 -0
- data/guides/output/i18n.html +1054 -0
- data/guides/output/images/belongs_to.png +0 -0
- data/guides/output/images/book_icon.gif +0 -0
- data/guides/output/images/bullet.gif +0 -0
- data/guides/output/images/challenge.png +0 -0
- data/guides/output/images/chapters_icon.gif +0 -0
- data/guides/output/images/check_bullet.gif +0 -0
- data/guides/output/images/credits_pic_blank.gif +0 -0
- data/guides/output/images/csrf.png +0 -0
- data/guides/output/images/customized_error_messages.png +0 -0
- data/guides/output/images/edge_badge.png +0 -0
- data/guides/output/images/error_messages.png +0 -0
- data/guides/output/images/feature_tile.gif +0 -0
- data/guides/output/images/footer_tile.gif +0 -0
- data/guides/output/images/fxn.png +0 -0
- data/guides/output/images/grey_bullet.gif +0 -0
- data/guides/output/images/habtm.png +0 -0
- data/guides/output/images/has_many.png +0 -0
- data/guides/output/images/has_many_through.png +0 -0
- data/guides/output/images/has_one.png +0 -0
- data/guides/output/images/has_one_through.png +0 -0
- data/guides/output/images/header_backdrop.png +0 -0
- data/guides/output/images/header_tile.gif +0 -0
- data/guides/output/images/i18n/demo_html_safe.png +0 -0
- data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translated_en.png +0 -0
- data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translation_missing.png +0 -0
- data/guides/output/images/i18n/demo_untranslated.png +0 -0
- data/guides/output/images/icons/README +5 -0
- data/guides/output/images/icons/callouts/1.png +0 -0
- data/guides/output/images/icons/callouts/10.png +0 -0
- data/guides/output/images/icons/callouts/11.png +0 -0
- data/guides/output/images/icons/callouts/12.png +0 -0
- data/guides/output/images/icons/callouts/13.png +0 -0
- data/guides/output/images/icons/callouts/14.png +0 -0
- data/guides/output/images/icons/callouts/15.png +0 -0
- data/guides/output/images/icons/callouts/2.png +0 -0
- data/guides/output/images/icons/callouts/3.png +0 -0
- data/guides/output/images/icons/callouts/4.png +0 -0
- data/guides/output/images/icons/callouts/5.png +0 -0
- data/guides/output/images/icons/callouts/6.png +0 -0
- data/guides/output/images/icons/callouts/7.png +0 -0
- data/guides/output/images/icons/callouts/8.png +0 -0
- data/guides/output/images/icons/callouts/9.png +0 -0
- data/guides/output/images/icons/caution.png +0 -0
- data/guides/output/images/icons/example.png +0 -0
- data/guides/output/images/icons/home.png +0 -0
- data/guides/output/images/icons/important.png +0 -0
- data/guides/output/images/icons/next.png +0 -0
- data/guides/output/images/icons/note.png +0 -0
- data/guides/output/images/icons/prev.png +0 -0
- data/guides/output/images/icons/tip.png +0 -0
- data/guides/output/images/icons/up.png +0 -0
- data/guides/output/images/icons/warning.png +0 -0
- data/guides/output/images/jaimeiniesta.jpg +0 -0
- data/guides/output/images/nav_arrow.gif +0 -0
- data/guides/output/images/polymorphic.png +0 -0
- data/guides/output/images/posts_index.png +0 -0
- data/guides/output/images/radar.png +0 -0
- data/guides/output/images/rails_guides_logo.gif +0 -0
- data/guides/output/images/rails_logo_remix.gif +0 -0
- data/guides/output/images/rails_welcome.png +0 -0
- data/guides/output/images/session_fixation.png +0 -0
- data/guides/output/images/tab_grey.gif +0 -0
- data/guides/output/images/tab_info.gif +0 -0
- data/guides/output/images/tab_note.gif +0 -0
- data/guides/output/images/tab_red.gif +0 -0
- data/guides/output/images/tab_yellow.gif +0 -0
- data/guides/output/images/tab_yellow.png +0 -0
- data/guides/output/images/validation_error_messages.png +0 -0
- data/guides/output/images/vijaydev.jpg +0 -0
- data/guides/output/index.html +300 -0
- data/guides/output/initialization.html +1087 -0
- data/guides/output/javascripts/guides.js +7 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
- data/guides/output/javascripts/syntaxhighlighter/shCore.js +17 -0
- data/guides/output/layout.html +312 -0
- data/guides/output/layouts_and_rendering.html +1257 -0
- data/guides/output/migrations.html +751 -0
- data/guides/output/nested_model_forms.html +350 -0
- data/guides/output/performance_testing.html +858 -0
- data/guides/output/plugins.html +590 -0
- data/guides/output/rails_application_templates.html +368 -0
- data/guides/output/rails_on_rack.html +408 -0
- data/guides/output/routing.html +1246 -0
- data/guides/output/ruby_on_rails_guides_guidelines.html +218 -0
- data/guides/output/security.html +968 -0
- data/guides/output/stylesheets/fixes.css +16 -0
- data/guides/output/stylesheets/main.css +445 -0
- data/guides/output/stylesheets/print.css +52 -0
- data/guides/output/stylesheets/reset.css +43 -0
- data/guides/output/stylesheets/style.css +13 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCore.css +226 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
- data/guides/output/testing.html +1182 -0
- data/guides/source/active_record_validations_callbacks.textile +3 -3
- data/guides/source/active_support_core_extensions.textile +2 -2
- data/guides/source/asset_pipeline.textile +7 -5
- data/guides/source/association_basics.textile +2 -4
- data/guides/source/command_line.textile +1 -1
- data/guides/source/configuring.textile +4 -2
- data/guides/source/contributing_to_ruby_on_rails.textile +6 -6
- data/guides/source/initialization.textile +2 -2
- data/guides/source/performance_testing.textile +1 -1
- data/guides/source/routing.textile +1 -1
- data/guides/source/security.textile +2 -2
- data/lib/rails/commands/server.rb +1 -1
- data/lib/rails/engine.rb +1 -1
- data/lib/rails/generators/app_base.rb +2 -1
- data/lib/rails/generators/base.rb +3 -3
- data/lib/rails/generators/rails/app/templates/gitignore +15 -5
- data/lib/rails/rack.rb +0 -1
- data/lib/rails/tasks/documentation.rake +7 -7
- data/lib/rails/tasks/misc.rake +0 -2
- data/lib/rails/test_unit/testing.rake +2 -0
- data/lib/rails/version.rb +2 -2
- metadata +495 -326
- data/CHANGELOG +0 -2371
- data/lib/rails/rack/content_length.rb +0 -38
@@ -0,0 +1,210 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
+
|
8
|
+
<title>Ruby on Rails Guides: Credits
|
9
|
+
</title>
|
10
|
+
|
11
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
12
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
|
13
|
+
|
14
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
|
15
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
|
16
|
+
|
17
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
|
18
|
+
</head>
|
19
|
+
<body class="guide">
|
20
|
+
<div id="topNav">
|
21
|
+
<div class="wrapper">
|
22
|
+
<strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
|
23
|
+
<a href="http://rubyonrails.org/">Overview</a> |
|
24
|
+
<a href="http://rubyonrails.org/download">Download</a> |
|
25
|
+
<a href="http://rubyonrails.org/deploy">Deploy</a> |
|
26
|
+
<a href="https://github.com/rails/rails">Code</a> |
|
27
|
+
<a href="http://rubyonrails.org/screencasts">Screencasts</a> |
|
28
|
+
<a href="http://rubyonrails.org/documentation">Documentation</a> |
|
29
|
+
<a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
|
30
|
+
<a href="http://rubyonrails.org/community">Community</a> |
|
31
|
+
<a href="http://weblog.rubyonrails.org/">Blog</a>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
<div id="header">
|
35
|
+
<div class="wrapper clearfix">
|
36
|
+
<h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
|
37
|
+
<p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
|
38
|
+
<ul class="nav">
|
39
|
+
<li><a href="index.html">Home</a></li>
|
40
|
+
<li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
|
41
|
+
<div id="guides" class="clearfix" style="display: none;">
|
42
|
+
<hr />
|
43
|
+
<dl class="L">
|
44
|
+
<dt>Start Here</dt>
|
45
|
+
<dd><a href="getting_started.html">Getting Started with Rails</a></dd>
|
46
|
+
<dt>Models</dt>
|
47
|
+
<dd><a href="migrations.html">Rails Database Migrations</a></dd>
|
48
|
+
<dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
|
49
|
+
<dd><a href="association_basics.html">Active Record Associations</a></dd>
|
50
|
+
<dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
|
51
|
+
<dt>Views</dt>
|
52
|
+
<dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
|
53
|
+
<dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
|
54
|
+
<dt>Controllers</dt>
|
55
|
+
<dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
|
56
|
+
<dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
|
57
|
+
</dl>
|
58
|
+
<dl class="R">
|
59
|
+
<dt>Digging Deeper</dt>
|
60
|
+
<dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
|
61
|
+
<dd><a href="i18n.html">Rails Internationalization API</a></dd>
|
62
|
+
<dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
|
63
|
+
<dd><a href="testing.html">Testing Rails Applications</a></dd>
|
64
|
+
<dd><a href="security.html">Securing Rails Applications</a></dd>
|
65
|
+
<dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
|
66
|
+
<dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
|
67
|
+
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
|
68
|
+
<dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
|
69
|
+
<dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
|
70
|
+
<dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
|
71
|
+
|
72
|
+
<dt>Extending Rails</dt>
|
73
|
+
<dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
|
74
|
+
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
|
75
|
+
<dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
|
76
|
+
|
77
|
+
<dt>Contributing to Ruby on Rails</dt>
|
78
|
+
<dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
|
79
|
+
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
|
80
|
+
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
|
81
|
+
|
82
|
+
<dt>Release Notes</dt>
|
83
|
+
<dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
|
84
|
+
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
|
85
|
+
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
|
86
|
+
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
|
87
|
+
</dl>
|
88
|
+
</div>
|
89
|
+
</li>
|
90
|
+
<li><a href="contributing_to_ruby_on_rails.html">Contribute</a></li>
|
91
|
+
<li><a href="credits.html">Credits</a></li>
|
92
|
+
</ul>
|
93
|
+
</div>
|
94
|
+
</div>
|
95
|
+
<hr class="hide" />
|
96
|
+
|
97
|
+
<div id="feature">
|
98
|
+
<div class="wrapper">
|
99
|
+
<h2>Credits</h2>
|
100
|
+
|
101
|
+
<p>We'd like to thank the following people for their tireless contributions to this project.</p>
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
</div>
|
107
|
+
</div>
|
108
|
+
|
109
|
+
<div id="container">
|
110
|
+
<div class="wrapper">
|
111
|
+
<div id="mainCol">
|
112
|
+
|
113
|
+
|
114
|
+
<h3 class="section">Rails Guides Reviewers</h3>
|
115
|
+
|
116
|
+
<div class="clearfix" id="vijaydev"><img alt="Vijay Dev" class="left pic" height="91" src="images/vijaydev.jpg" width="91"></img><h3>Vijay Dev</h3><p>
|
117
|
+
Vijayakumar, found as Vijay Dev on the web, is a web applications developer and an open source enthusiast who lives in Chennai, India. He started using Rails in 2009 and began actively contributing to Rails documentation in late 2010. He <a href="https://twitter.com/vijay_dev">tweets</a> a lot and also <a href="http://vijaydev.wordpress.com">blogs</a>.
|
118
|
+
</p></div>
|
119
|
+
<div class="clearfix" id="fxn"><img alt="Xavier Noria" class="left pic" height="91" src="images/fxn.png" width="91"></img><h3>Xavier Noria</h3><p>
|
120
|
+
Xavier Noria has been into Ruby on Rails since 2005. He is a Rails core team member and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Xavier is currently an independent Ruby on Rails consultant. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as "fxn".
|
121
|
+
</p></div>
|
122
|
+
<h3 class="section">Rails Guides Designers</h3>
|
123
|
+
|
124
|
+
<div class="clearfix" id="jz"><img alt="Jason Zimdars" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Jason Zimdars</h3><p>
|
125
|
+
Jason Zimdars is an experienced creative director and web designer who has lead UI and UX design for numerous websites and web applications. You can see more of his design and writing at <a href="http://www.thinkcage.com/">Thinkcage.com</a> or follow him on <a href="http://twitter.com/JZ">Twitter</a>.
|
126
|
+
</p></div>
|
127
|
+
<h3 class="section">Rails Guides Authors</h3>
|
128
|
+
|
129
|
+
<div class="clearfix" id="radar"><img alt="Ryan Bigg" class="left pic" height="91" src="images/radar.png" width="91"></img><h3>Ryan Bigg</h3><p>
|
130
|
+
Ryan Bigg works as a consultant at <a href="http://rubyx.com">RubyX</a> and has been working with Rails since 2006. He's co-authoring a book called <a href="http://manning.com/katz">Rails 3 in Action</a> and he's written many gems which can be seen on <a href="http://github.com/radar">his GitHub page</a> and he also tweets prolifically as <a href="http://twitter.com/ryanbigg">@ryanbigg</a>.
|
131
|
+
</p></div>
|
132
|
+
<div class="clearfix" id="fcheung"><img alt="Frederick Cheung" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Frederick Cheung</h3><p>
|
133
|
+
Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006. He is based in Cambridge (UK) and when not consuming fine ales he blogs at <a href="http://www.spacevatican.org">spacevatican.org</a>.
|
134
|
+
</p></div>
|
135
|
+
<div class="clearfix" id="toretore"><img alt="Tore Darell" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Tore Darell</h3><p>
|
136
|
+
Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails and unobtrusive JavaScript. His home on the internet is his blog <a href="http://tore.darell.no">Sneaky Abstractions</a>.
|
137
|
+
</p></div>
|
138
|
+
<div class="clearfix" id="zilkey"><img alt="Jeff Dean" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Jeff Dean</h3><p>
|
139
|
+
Jeff Dean is a software engineer with <a href="http://pivotallabs.com">Pivotal Labs</a>.
|
140
|
+
</p></div>
|
141
|
+
<div class="clearfix" id="mgunderloy"><img alt="Mike Gunderloy" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Mike Gunderloy</h3><p>
|
142
|
+
Mike Gunderloy is a consultant with <a href="http://www.actionrails.com">ActionRails</a>. He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at <a href="http://afreshcup.com">A Fresh Cup</a> and he <a href="http://twitter.com/MikeG1">twitters</a> too much.
|
143
|
+
</p></div>
|
144
|
+
<div class="clearfix" id="raasdnil"><img alt="Mikel Lindsaar" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Mikel Lindsaar</h3><p>
|
145
|
+
Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a href="https://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
|
146
|
+
</p></div>
|
147
|
+
<div class="clearfix" id="cmarques"><img alt="Cássio Marques" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Cássio Marques</h3><p>
|
148
|
+
Cássio Marques is a Brazilian software developer working with different programming languages such as Ruby, JavaScript, CPP and Java, as an independent consultant. He blogs at <a href="http://cassiomarques.wordpress.com">/* CODIFICANDO */</a>, which is mainly written in Portuguese, but will soon get a new section for posts with English translation.
|
149
|
+
</p></div>
|
150
|
+
<div class="clearfix" id="bensie"><img alt="James Miller" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>James Miller</h3><p>
|
151
|
+
James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA. You can find James on GitHub, Gmail, Twitter, and Freenode as "bensie".
|
152
|
+
</p></div>
|
153
|
+
<div class="clearfix" id="lifo"><img alt="Pratik Naik" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Pratik Naik</h3><p>
|
154
|
+
Pratik Naik is a Ruby on Rails consultant with <a href="http://www.actionrails.com">ActionRails</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 an active <a href="http://twitter.com/lifo">twitter account</a>.
|
155
|
+
</p></div>
|
156
|
+
<div class="clearfix" id="miloops"><img alt="Emilio Tagua" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Emilio Tagua</h3><p>
|
157
|
+
Emilio Tagua —a.k.a. miloops— is an Argentinian entrepreneur, developer, open source contributor and Rails evangelist. Cofounder of <a href="http://eventioz.com">Eventioz</a>. He has been using Rails since 2006 and contributing since early 2008. Can be found at gmail, twitter, freenode, everywhere as "miloops".
|
158
|
+
</p></div>
|
159
|
+
<div class="clearfix" id="hawe"><img alt="Heiko Webers" class="left pic" height="91" src="images/credits_pic_blank.gif" width="91"></img><h3>Heiko Webers</h3><p>
|
160
|
+
Heiko Webers is the founder of <a href="http://www.bauland42.de">bauland42</a>, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the <a href="http://www.rorsecurity.info">Ruby on Rails Security Project</a>. After 10 years of desktop application development, Heiko has rarely looked back.
|
161
|
+
</p></div>
|
162
|
+
|
163
|
+
<h3>Feedback</h3>
|
164
|
+
<p>
|
165
|
+
You're encouraged to help improve the quality of this guide.
|
166
|
+
</p>
|
167
|
+
<p>
|
168
|
+
If you see any typos or factual errors you are confident to
|
169
|
+
patch, please clone <a href="https://github.com/lifo/docrails">docrails</a>
|
170
|
+
and push the change yourself. That branch of Rails has public write access.
|
171
|
+
Commits are still reviewed, but that happens after you've submitted your
|
172
|
+
contribution. <a href="https://github.com/lifo/docrails">docrails</a> is
|
173
|
+
cross-merged with master periodically.
|
174
|
+
</p>
|
175
|
+
<p>
|
176
|
+
You may also find incomplete content, or stuff that is not up to date.
|
177
|
+
Please do add any missing documentation for master. Check the
|
178
|
+
<a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
|
179
|
+
for style and conventions.
|
180
|
+
</p>
|
181
|
+
<p>
|
182
|
+
If for whatever reason you spot something to fix but cannot patch it yourself, please
|
183
|
+
<a href="https://github.com/rails/rails/issues">open an issue</a>.
|
184
|
+
</p>
|
185
|
+
<p>And last but not least, any kind of discussion regarding Ruby on Rails
|
186
|
+
documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
|
187
|
+
</p>
|
188
|
+
</div>
|
189
|
+
</div>
|
190
|
+
</div>
|
191
|
+
|
192
|
+
<hr class="hide" />
|
193
|
+
<div id="footer">
|
194
|
+
<div class="wrapper">
|
195
|
+
<p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
|
196
|
+
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
|
197
|
+
</div>
|
198
|
+
</div>
|
199
|
+
|
200
|
+
<script type="text/javascript" src="javascripts/guides.js"></script>
|
201
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
|
202
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
|
203
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
|
204
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
205
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
206
|
+
<script type="text/javascript">
|
207
|
+
SyntaxHighlighter.all()
|
208
|
+
</script>
|
209
|
+
</body>
|
210
|
+
</html>
|
@@ -0,0 +1,791 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
+
|
8
|
+
<title>Ruby on Rails Guides: Debugging Rails Applications</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
11
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
|
12
|
+
|
13
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
|
14
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
|
15
|
+
|
16
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
|
17
|
+
</head>
|
18
|
+
<body class="guide">
|
19
|
+
<div id="topNav">
|
20
|
+
<div class="wrapper">
|
21
|
+
<strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
|
22
|
+
<a href="http://rubyonrails.org/">Overview</a> |
|
23
|
+
<a href="http://rubyonrails.org/download">Download</a> |
|
24
|
+
<a href="http://rubyonrails.org/deploy">Deploy</a> |
|
25
|
+
<a href="https://github.com/rails/rails">Code</a> |
|
26
|
+
<a href="http://rubyonrails.org/screencasts">Screencasts</a> |
|
27
|
+
<a href="http://rubyonrails.org/documentation">Documentation</a> |
|
28
|
+
<a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
|
29
|
+
<a href="http://rubyonrails.org/community">Community</a> |
|
30
|
+
<a href="http://weblog.rubyonrails.org/">Blog</a>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
<div id="header">
|
34
|
+
<div class="wrapper clearfix">
|
35
|
+
<h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
|
36
|
+
<p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
|
37
|
+
<ul class="nav">
|
38
|
+
<li><a href="index.html">Home</a></li>
|
39
|
+
<li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
|
40
|
+
<div id="guides" class="clearfix" style="display: none;">
|
41
|
+
<hr />
|
42
|
+
<dl class="L">
|
43
|
+
<dt>Start Here</dt>
|
44
|
+
<dd><a href="getting_started.html">Getting Started with Rails</a></dd>
|
45
|
+
<dt>Models</dt>
|
46
|
+
<dd><a href="migrations.html">Rails Database Migrations</a></dd>
|
47
|
+
<dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
|
48
|
+
<dd><a href="association_basics.html">Active Record Associations</a></dd>
|
49
|
+
<dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
|
50
|
+
<dt>Views</dt>
|
51
|
+
<dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
|
52
|
+
<dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
|
53
|
+
<dt>Controllers</dt>
|
54
|
+
<dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
|
55
|
+
<dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
|
56
|
+
</dl>
|
57
|
+
<dl class="R">
|
58
|
+
<dt>Digging Deeper</dt>
|
59
|
+
<dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
|
60
|
+
<dd><a href="i18n.html">Rails Internationalization API</a></dd>
|
61
|
+
<dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
|
62
|
+
<dd><a href="testing.html">Testing Rails Applications</a></dd>
|
63
|
+
<dd><a href="security.html">Securing Rails Applications</a></dd>
|
64
|
+
<dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
|
65
|
+
<dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
|
66
|
+
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
|
67
|
+
<dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
|
68
|
+
<dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
|
69
|
+
<dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
|
70
|
+
|
71
|
+
<dt>Extending Rails</dt>
|
72
|
+
<dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
|
73
|
+
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
|
74
|
+
<dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
|
75
|
+
|
76
|
+
<dt>Contributing to Ruby on Rails</dt>
|
77
|
+
<dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
|
78
|
+
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
|
79
|
+
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
|
80
|
+
|
81
|
+
<dt>Release Notes</dt>
|
82
|
+
<dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
|
83
|
+
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
|
84
|
+
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
|
85
|
+
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
|
86
|
+
</dl>
|
87
|
+
</div>
|
88
|
+
</li>
|
89
|
+
<li><a href="contributing_to_ruby_on_rails.html">Contribute</a></li>
|
90
|
+
<li><a href="credits.html">Credits</a></li>
|
91
|
+
</ul>
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
<hr class="hide" />
|
95
|
+
|
96
|
+
<div id="feature">
|
97
|
+
<div class="wrapper">
|
98
|
+
<h2>Debugging Rails Applications</h2>
|
99
|
+
<p>This guide introduces techniques for debugging Ruby on Rails applications. By referring to this guide, you will be able to:</p>
|
100
|
+
<ul>
|
101
|
+
<li>Understand the purpose of debugging</li>
|
102
|
+
<li>Track down problems and issues in your application that your tests aren’t identifying</li>
|
103
|
+
<li>Learn the different ways of debugging</li>
|
104
|
+
<li>Analyze the stack trace</li>
|
105
|
+
</ul>
|
106
|
+
|
107
|
+
<div id="subCol">
|
108
|
+
<h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
|
109
|
+
<ol class="chapters">
|
110
|
+
<li><a href="#view-helpers-for-debugging">View Helpers for Debugging</a><ul><li><a href="#debug"><tt>debug</tt></a></li> <li><a href="#to_yaml"><tt>to_yaml</tt></a></li> <li><a href="#inspect"><tt>inspect</tt></a></li></ul></li><li><a href="#the-logger">The Logger</a><ul><li><a href="#what-is-the-logger">What is the Logger?</a></li> <li><a href="#log-levels">Log Levels</a></li> <li><a href="#sending-messages">Sending Messages</a></li></ul></li><li><a href="#debugging-with-ruby-debug">Debugging with <tt>ruby-debug</tt></a><ul><li><a href="#setup">Setup</a></li> <li><a href="#the-shell">The Shell</a></li> <li><a href="#the-context">The Context</a></li> <li><a href="#threads">Threads</a></li> <li><a href="#inspecting-variables">Inspecting Variables</a></li> <li><a href="#step-by-step">Step by Step</a></li> <li><a href="#breakpoints">Breakpoints</a></li> <li><a href="#catching-exceptions">Catching Exceptions</a></li> <li><a href="#resuming-execution">Resuming Execution</a></li> <li><a href="#editing">Editing</a></li> <li><a href="#quitting">Quitting</a></li> <li><a href="#settings">Settings</a></li></ul></li><li><a href="#debugging-memory-leaks">Debugging Memory Leaks</a><ul><li><a href="#bleakhouse">BleakHouse</a></li> <li><a href="#valgrind">Valgrind</a></li></ul></li><li><a href="#plugins-for-debugging">Plugins for Debugging</a></li><li><a href="#references">References</a></li></ol></div>
|
111
|
+
</div>
|
112
|
+
</div>
|
113
|
+
|
114
|
+
<div id="container">
|
115
|
+
<div class="wrapper">
|
116
|
+
<div id="mainCol">
|
117
|
+
<h3 id="view-helpers-for-debugging">1 View Helpers for Debugging</h3>
|
118
|
+
<p>One common task is to inspect the contents of a variable. In Rails, you can do this with three methods:</p>
|
119
|
+
<ul>
|
120
|
+
<li><tt>debug</tt></li>
|
121
|
+
<li><tt>to_yaml</tt></li>
|
122
|
+
<li><tt>inspect</tt></li>
|
123
|
+
</ul>
|
124
|
+
<h4 id="debug">1.1 <tt>debug</tt></h4>
|
125
|
+
<p>The <tt>debug</tt> helper will return a <pre>-tag that renders the object using the <span class="caps">YAML</span> format. This will generate human-readable data from any object. For example, if you have this code in a view:</p>
|
126
|
+
<div class="code_container">
|
127
|
+
<pre class="brush: xml; gutter: false; toolbar: false">
|
128
|
+
<%= debug @post %>
|
129
|
+
<p>
|
130
|
+
<b>Title:</b>
|
131
|
+
<%=h @post.title %>
|
132
|
+
</p>
|
133
|
+
</pre>
|
134
|
+
</div>
|
135
|
+
<p>You’ll see something like this:</p>
|
136
|
+
<div class="code_container">
|
137
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
138
|
+
--- !ruby/object:Post
|
139
|
+
attributes:
|
140
|
+
updated_at: 2008-09-05 22:55:47
|
141
|
+
body: It's a very helpful guide for debugging your Rails app.
|
142
|
+
title: Rails debugging guide
|
143
|
+
published: t
|
144
|
+
id: "1"
|
145
|
+
created_at: 2008-09-05 22:55:47
|
146
|
+
attributes_cache: {}
|
147
|
+
|
148
|
+
|
149
|
+
Title: Rails debugging guide
|
150
|
+
</pre>
|
151
|
+
</div>
|
152
|
+
<h4 id="to_yaml">1.2 <tt>to_yaml</tt></h4>
|
153
|
+
<p>Displaying an instance variable, or any other object or method, in <span class="caps">YAML</span> format can be achieved this way:</p>
|
154
|
+
<div class="code_container">
|
155
|
+
<pre class="brush: xml; gutter: false; toolbar: false">
|
156
|
+
<%= simple_format @post.to_yaml %>
|
157
|
+
<p>
|
158
|
+
<b>Title:</b>
|
159
|
+
<%=h @post.title %>
|
160
|
+
</p>
|
161
|
+
</pre>
|
162
|
+
</div>
|
163
|
+
<p>The <tt>to_yaml</tt> method converts the method to <span class="caps">YAML</span> format leaving it more readable, and then the <tt>simple_format</tt> helper is used to render each line as in the console. This is how <tt>debug</tt> method does its magic.</p>
|
164
|
+
<p>As a result of this, you will have something like this in your view:</p>
|
165
|
+
<div class="code_container">
|
166
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
167
|
+
--- !ruby/object:Post
|
168
|
+
attributes:
|
169
|
+
updated_at: 2008-09-05 22:55:47
|
170
|
+
body: It's a very helpful guide for debugging your Rails app.
|
171
|
+
title: Rails debugging guide
|
172
|
+
published: t
|
173
|
+
id: "1"
|
174
|
+
created_at: 2008-09-05 22:55:47
|
175
|
+
attributes_cache: {}
|
176
|
+
|
177
|
+
Title: Rails debugging guide
|
178
|
+
</pre>
|
179
|
+
</div>
|
180
|
+
<h4 id="inspect">1.3 <tt>inspect</tt></h4>
|
181
|
+
<p>Another useful method for displaying object values is <tt>inspect</tt>, especially when working with arrays or hashes. This will print the object value as a string. For example:</p>
|
182
|
+
<div class="code_container">
|
183
|
+
<pre class="brush: xml; gutter: false; toolbar: false">
|
184
|
+
<%= [1, 2, 3, 4, 5].inspect %>
|
185
|
+
<p>
|
186
|
+
<b>Title:</b>
|
187
|
+
<%=h @post.title %>
|
188
|
+
</p>
|
189
|
+
</pre>
|
190
|
+
</div>
|
191
|
+
<p>Will be rendered as follows:</p>
|
192
|
+
<pre>
|
193
|
+
[1, 2, 3, 4, 5]
|
194
|
+
|
195
|
+
Title: Rails debugging guide
|
196
|
+
</pre>
|
197
|
+
<h3 id="the-logger">2 The Logger</h3>
|
198
|
+
<p>It can also be useful to save information to log files at runtime. Rails maintains a separate log file for each runtime environment.</p>
|
199
|
+
<h4 id="what-is-the-logger">2.1 What is the Logger?</h4>
|
200
|
+
<p>Rails makes use of Ruby’s standard <tt>logger</tt> to write log information. You can also substitute another logger such as <tt>Log4r</tt> if you wish.</p>
|
201
|
+
<p>You can specify an alternative logger in your <tt>environment.rb</tt> or any environment file:</p>
|
202
|
+
<div class="code_container">
|
203
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
204
|
+
Rails.logger = Logger.new(STDOUT)
|
205
|
+
Rails.logger = Log4r::Logger.new("Application Log")
|
206
|
+
</pre>
|
207
|
+
</div>
|
208
|
+
<p>Or in the <tt>Initializer</tt> section, add <em>any</em> of the following</p>
|
209
|
+
<div class="code_container">
|
210
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
211
|
+
config.logger = Logger.new(STDOUT)
|
212
|
+
config.logger = Log4r::Logger.new("Application Log")
|
213
|
+
</pre>
|
214
|
+
</div>
|
215
|
+
<div class="info"><p>By default, each log is created under <tt>Rails.root/log/</tt> and the log file name is <tt>environment_name.log</tt>.</p></div>
|
216
|
+
<h4 id="log-levels">2.2 Log Levels</h4>
|
217
|
+
<p>When something is logged it’s printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the <tt>Rails.logger.level</tt> method.</p>
|
218
|
+
<p>The available log levels are: <tt>:debug</tt>, <tt>:info</tt>, <tt>:warn</tt>, <tt>:error</tt>, and <tt>:fatal</tt>, corresponding to the log level numbers from 0 up to 4 respectively. To change the default log level, use</p>
|
219
|
+
<div class="code_container">
|
220
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
221
|
+
config.log_level = :warn # In any environment initializer, or
|
222
|
+
Rails.logger.level = 0 # at any time
|
223
|
+
</pre>
|
224
|
+
</div>
|
225
|
+
<p>This is useful when you want to log under development or staging, but you don’t want to flood your production log with unnecessary information.</p>
|
226
|
+
<div class="info"><p>The default Rails log level is <tt>info</tt> in production mode and <tt>debug</tt> in development and test mode.</p></div>
|
227
|
+
<h4 id="sending-messages">2.3 Sending Messages</h4>
|
228
|
+
<p>To write in the current log use the <tt>logger.(debug|info|warn|error|fatal)</tt> method from within a controller, model or mailer:</p>
|
229
|
+
<div class="code_container">
|
230
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
231
|
+
logger.debug "Person attributes hash: #{@person.attributes.inspect}"
|
232
|
+
logger.info "Processing the request..."
|
233
|
+
logger.fatal "Terminating application, raised unrecoverable error!!!"
|
234
|
+
</pre>
|
235
|
+
</div>
|
236
|
+
<p>Here’s an example of a method instrumented with extra logging:</p>
|
237
|
+
<div class="code_container">
|
238
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
239
|
+
class PostsController < ApplicationController
|
240
|
+
# ...
|
241
|
+
|
242
|
+
def create
|
243
|
+
@post = Post.new(params[:post])
|
244
|
+
logger.debug "New post: #{@post.attributes.inspect}"
|
245
|
+
logger.debug "Post should be valid: #{@post.valid?}"
|
246
|
+
|
247
|
+
if @post.save
|
248
|
+
flash[:notice] = 'Post was successfully created.'
|
249
|
+
logger.debug "The post was saved and now the user is going to be redirected..."
|
250
|
+
redirect_to(@post)
|
251
|
+
else
|
252
|
+
render :action => "new"
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
# ...
|
257
|
+
end
|
258
|
+
</pre>
|
259
|
+
</div>
|
260
|
+
<p>Here’s an example of the log generated by this method:</p>
|
261
|
+
<div class="code_container">
|
262
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
263
|
+
Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
|
264
|
+
Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl
|
265
|
+
vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4
|
266
|
+
Parameters: {"commit"=>"Create", "post"=>{"title"=>"Debugging Rails",
|
267
|
+
"body"=>"I'm learning how to print in logs!!!", "published"=>"0"},
|
268
|
+
"authenticity_token"=>"2059c1286e93402e389127b1153204e0d1e275dd", "action"=>"create", "controller"=>"posts"}
|
269
|
+
New post: {"updated_at"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!",
|
270
|
+
"published"=>false, "created_at"=>nil}
|
271
|
+
Post should be valid: true
|
272
|
+
Post Create (0.000443) INSERT INTO "posts" ("updated_at", "title", "body", "published",
|
273
|
+
"created_at") VALUES('2008-09-08 14:52:54', 'Debugging Rails',
|
274
|
+
'I''m learning how to print in logs!!!', 'f', '2008-09-08 14:52:54')
|
275
|
+
The post was saved and now the user is going to be redirected...
|
276
|
+
Redirected to #<Post:0x20af760>
|
277
|
+
Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
|
278
|
+
</pre>
|
279
|
+
</div>
|
280
|
+
<p>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.</p>
|
281
|
+
<h3 id="debugging-with-ruby-debug">3 Debugging with <tt>ruby-debug</tt></h3>
|
282
|
+
<p>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.</p>
|
283
|
+
<p>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.</p>
|
284
|
+
<h4 id="setup">3.1 Setup</h4>
|
285
|
+
<p>The debugger used by Rails, <tt>ruby-debug</tt>, comes as a gem. To install it, just run:</p>
|
286
|
+
<div class="code_container">
|
287
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
288
|
+
$ sudo gem install ruby-debug
|
289
|
+
</pre>
|
290
|
+
</div>
|
291
|
+
<div class="info"><p>If you are using Ruby 1.9, you can install a compatible version of <tt>ruby-debug</tt> by running <tt>sudo gem install ruby-debug19</tt></p></div>
|
292
|
+
<p>In case you want to download a particular version or get the source code, refer to the <a href="http://rubyforge.org/projects/ruby-debug/">project’s page on rubyforge</a>.</p>
|
293
|
+
<p>Rails has had built-in support for ruby-debug since Rails 2.0. Inside any Rails application you can invoke the debugger by calling the <tt>debugger</tt> method.</p>
|
294
|
+
<p>Here’s an example:</p>
|
295
|
+
<div class="code_container">
|
296
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
297
|
+
class PeopleController < ApplicationController
|
298
|
+
def new
|
299
|
+
debugger
|
300
|
+
@person = Person.new
|
301
|
+
end
|
302
|
+
end
|
303
|
+
</pre>
|
304
|
+
</div>
|
305
|
+
<p>If you see the message in the console or logs:</p>
|
306
|
+
<div class="code_container">
|
307
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
308
|
+
***** Debugger requested, but was not available: Start server with --debugger to enable *****
|
309
|
+
</pre>
|
310
|
+
</div>
|
311
|
+
<p>Make sure you have started your web server with the option <tt>--debugger</tt>:</p>
|
312
|
+
<div class="code_container">
|
313
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
314
|
+
$ rails server --debugger
|
315
|
+
=> Booting WEBrick
|
316
|
+
=> Rails 3.0.0 application starting on http://0.0.0.0:3000
|
317
|
+
=> Debugger enabled
|
318
|
+
...
|
319
|
+
</pre>
|
320
|
+
</div>
|
321
|
+
<div class="info"><p>In development mode, you can dynamically <tt>require \'ruby-debug\'</tt> instead of restarting the server, if it was started without <tt>--debugger</tt>.</p></div>
|
322
|
+
<h4 id="the-shell">3.2 The Shell</h4>
|
323
|
+
<p>As soon as your application calls the <tt>debugger</tt> 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 ruby-debug’s prompt <tt>(rdb:n)</tt>. The <em>n</em> is the thread number. The prompt will also show you the next line of code that is waiting to run.</p>
|
324
|
+
<p>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.</p>
|
325
|
+
<p>For example:</p>
|
326
|
+
<div class="code_container">
|
327
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
328
|
+
@posts = Post.all
|
329
|
+
(rdb:7)
|
330
|
+
</pre>
|
331
|
+
</div>
|
332
|
+
<p>Now it’s time to explore and dig into your application. A good place to start is by asking the debugger for help… so type: <tt>help</tt> (You didn’t see that coming, right?)</p>
|
333
|
+
<div class="code_container">
|
334
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
335
|
+
(rdb:7) help
|
336
|
+
ruby-debug help v0.10.2
|
337
|
+
Type 'help <command-name>' for help on a specific command
|
338
|
+
|
339
|
+
Available commands:
|
340
|
+
backtrace delete enable help next quit show trace
|
341
|
+
break disable eval info p reload source undisplay
|
342
|
+
catch display exit irb pp restart step up
|
343
|
+
condition down finish list ps save thread var
|
344
|
+
continue edit frame method putl set tmate where
|
345
|
+
</pre>
|
346
|
+
</div>
|
347
|
+
<div class="info"><p>To view the help menu for any command use <tt>help <command-name></tt> in active debug mode. For example: <em><tt>help var</tt></em></p></div>
|
348
|
+
<p>The next command to learn is one of the most useful: <tt>list</tt>. You can also abbreviate ruby-debug commands by supplying just enough letters to distinguish them from other commands, so you can also use <tt>l</tt> for the <tt>list</tt> command.</p>
|
349
|
+
<p>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 <tt>=></tt>.</p>
|
350
|
+
<div class="code_container">
|
351
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
352
|
+
(rdb:7) list
|
353
|
+
[1, 10] in /PathToProject/posts_controller.rb
|
354
|
+
1 class PostsController < ApplicationController
|
355
|
+
2 # GET /posts
|
356
|
+
3 # GET /posts.json
|
357
|
+
4 def index
|
358
|
+
5 debugger
|
359
|
+
=> 6 @posts = Post.all
|
360
|
+
7
|
361
|
+
8 respond_to do |format|
|
362
|
+
9 format.html # index.html.erb
|
363
|
+
10 format.json { render :json => @posts }
|
364
|
+
</pre>
|
365
|
+
</div>
|
366
|
+
<p>If you repeat the <tt>list</tt> command, this time using just <tt>l</tt>, the next ten lines of the file will be printed out.</p>
|
367
|
+
<div class="code_container">
|
368
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
369
|
+
(rdb:7) l
|
370
|
+
[11, 20] in /PathTo/project/app/controllers/posts_controller.rb
|
371
|
+
11 end
|
372
|
+
12 end
|
373
|
+
13
|
374
|
+
14 # GET /posts/1
|
375
|
+
15 # GET /posts/1.json
|
376
|
+
16 def show
|
377
|
+
17 @post = Post.find(params[:id])
|
378
|
+
18
|
379
|
+
19 respond_to do |format|
|
380
|
+
20 format.html # show.html.erb
|
381
|
+
</pre>
|
382
|
+
</div>
|
383
|
+
<p>And so on until the end of the current file. When the end of file is reached, the <tt>list</tt> command will start again from the beginning of the file and continue again up to the end, treating the file as a circular buffer.</p>
|
384
|
+
<p>On the other hand, to see the previous ten lines you should type <tt>list-</tt> (or <tt>l-</tt>)</p>
|
385
|
+
<div class="code_container">
|
386
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
387
|
+
(rdb:7) l-
|
388
|
+
[1, 10] in /PathToProject/posts_controller.rb
|
389
|
+
1 class PostsController < ApplicationController
|
390
|
+
2 # GET /posts
|
391
|
+
3 # GET /posts.json
|
392
|
+
4 def index
|
393
|
+
5 debugger
|
394
|
+
6 @posts = Post.all
|
395
|
+
7
|
396
|
+
8 respond_to do |format|
|
397
|
+
9 format.html # index.html.erb
|
398
|
+
10 format.json { render :json => @posts }
|
399
|
+
</pre>
|
400
|
+
</div>
|
401
|
+
<p>This way you can move inside the file, being able to see the code above and over the line you added the <tt>debugger</tt>.
|
402
|
+
Finally, to see where you are in the code again you can type <tt>list=</tt></p>
|
403
|
+
<div class="code_container">
|
404
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
405
|
+
(rdb:7) list=
|
406
|
+
[1, 10] in /PathToProject/posts_controller.rb
|
407
|
+
1 class PostsController < ApplicationController
|
408
|
+
2 # GET /posts
|
409
|
+
3 # GET /posts.json
|
410
|
+
4 def index
|
411
|
+
5 debugger
|
412
|
+
=> 6 @posts = Post.all
|
413
|
+
7
|
414
|
+
8 respond_to do |format|
|
415
|
+
9 format.html # index.html.erb
|
416
|
+
10 format.json { render :json => @posts }
|
417
|
+
</pre>
|
418
|
+
</div>
|
419
|
+
<h4 id="the-context">3.3 The Context</h4>
|
420
|
+
<p>When you start debugging your application, you will be placed in different contexts as you go through the different parts of the stack.</p>
|
421
|
+
<p>ruby-debug 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.</p>
|
422
|
+
<p>At any time you can call the <tt>backtrace</tt> command (or its alias <tt>where</tt>) 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 <tt>backtrace</tt> will supply the answer.</p>
|
423
|
+
<div class="code_container">
|
424
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
425
|
+
(rdb:5) where
|
426
|
+
#0 PostsController.index
|
427
|
+
at line /PathTo/project/app/controllers/posts_controller.rb:6
|
428
|
+
#1 Kernel.send
|
429
|
+
at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
|
430
|
+
#2 ActionController::Base.perform_action_without_filters
|
431
|
+
at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
|
432
|
+
#3 ActionController::Filters::InstanceMethods.call_filters(chain#ActionController::Fil...,...)
|
433
|
+
at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb:617
|
434
|
+
...
|
435
|
+
</pre>
|
436
|
+
</div>
|
437
|
+
<p>You move anywhere you want in this trace (thus changing the context) by using the <tt>frame _n_</tt> command, where <em>n</em> is the specified frame number.</p>
|
438
|
+
<div class="code_container">
|
439
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
440
|
+
(rdb:5) frame 2
|
441
|
+
#2 ActionController::Base.perform_action_without_filters
|
442
|
+
at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
|
443
|
+
</pre>
|
444
|
+
</div>
|
445
|
+
<p>The available variables are the same as if you were running the code line by line. After all, that’s what debugging is.</p>
|
446
|
+
<p>Moving up and down the stack frame: You can use <tt>up [n]</tt> (<tt>u</tt> for abbreviated) and <tt>down [n]</tt> commands in order to change the context <em>n</em> frames up or down the stack respectively. <em>n</em> defaults to one. Up in this case is towards higher-numbered stack frames, and down is towards lower-numbered stack frames.</p>
|
447
|
+
<h4 id="threads">3.4 Threads</h4>
|
448
|
+
<p>The debugger can list, stop, resume and switch between running threads by using the command <tt>thread</tt> (or the abbreviated <tt>th</tt>). This command has a handful of options:</p>
|
449
|
+
<ul>
|
450
|
+
<li><tt>thread</tt> shows the current thread.</li>
|
451
|
+
<li><tt>thread list</tt> is used to list all threads and their statuses. The plus + character and the number indicates the current thread of execution.</li>
|
452
|
+
<li><tt>thread stop _n_</tt> stop thread <em>n</em>.</li>
|
453
|
+
<li><tt>thread resume _n_</tt> resumes thread <em>n</em>.</li>
|
454
|
+
<li><tt>thread switch _n_</tt> switches the current thread context to <em>n</em>.</li>
|
455
|
+
</ul>
|
456
|
+
<p>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.</p>
|
457
|
+
<h4 id="inspecting-variables">3.5 Inspecting Variables</h4>
|
458
|
+
<p>Any expression can be evaluated in the current context. To evaluate an expression, just type it!</p>
|
459
|
+
<p>This example shows how you can print the instance_variables defined within the current context:</p>
|
460
|
+
<div class="code_container">
|
461
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
462
|
+
@posts = Post.all
|
463
|
+
(rdb:11) instance_variables
|
464
|
+
["@_response", "@action_name", "@url", "@_session", "@_cookies", "@performed_render", "@_flash", "@template", "@_params", "@before_filter_chain_aborted", "@request_origin", "@_headers", "@performed_redirect", "@_request"]
|
465
|
+
</pre>
|
466
|
+
</div>
|
467
|
+
<p>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 <tt>next</tt> (you’ll learn more about this command later in this guide).</p>
|
468
|
+
<div class="code_container">
|
469
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
470
|
+
(rdb:11) next
|
471
|
+
Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET]
|
472
|
+
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e
|
473
|
+
Parameters: {"action"=>"index", "controller"=>"posts"}
|
474
|
+
/PathToProject/posts_controller.rb:8
|
475
|
+
respond_to do |format|
|
476
|
+
</pre>
|
477
|
+
</div>
|
478
|
+
<p>And then ask again for the instance_variables:</p>
|
479
|
+
<div class="code_container">
|
480
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
481
|
+
(rdb:11) instance_variables.include? "@posts"
|
482
|
+
true
|
483
|
+
</pre>
|
484
|
+
</div>
|
485
|
+
<p>Now <tt>@posts</tt> is included in the instance variables, because the line defining it was executed.</p>
|
486
|
+
<div class="info"><p>You can also step into <strong>irb</strong> mode with the command <tt>irb</tt> (of course!). This way an irb session will be started within the context you invoked it. But be warned: this is an experimental feature.</p></div>
|
487
|
+
<p>The <tt>var</tt> method is the most convenient way to show variables and their values:</p>
|
488
|
+
<div class="code_container">
|
489
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
490
|
+
var
|
491
|
+
(rdb:1) v[ar] const <object> show constants of object
|
492
|
+
(rdb:1) v[ar] g[lobal] show global variables
|
493
|
+
(rdb:1) v[ar] i[nstance] <object> show instance variables of object
|
494
|
+
(rdb:1) v[ar] l[ocal] show local variables
|
495
|
+
</pre>
|
496
|
+
</div>
|
497
|
+
<p>This is a great way to inspect the values of the current context variables. For example:</p>
|
498
|
+
<div class="code_container">
|
499
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
500
|
+
(rdb:9) var local
|
501
|
+
__dbg_verbose_save => false
|
502
|
+
</pre>
|
503
|
+
</div>
|
504
|
+
<p>You can also inspect for an object method this way:</p>
|
505
|
+
<div class="code_container">
|
506
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
507
|
+
(rdb:9) var instance Post.new
|
508
|
+
@attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"...
|
509
|
+
@attributes_cache = {}
|
510
|
+
@new_record = true
|
511
|
+
</pre>
|
512
|
+
</div>
|
513
|
+
<div class="info"><p>The commands <tt>p</tt> (print) and <tt>pp</tt> (pretty print) can be used to evaluate Ruby expressions and display the value of variables to the console.</p></div>
|
514
|
+
<p>You can use also <tt>display</tt> to start watching variables. This is a good way of tracking the values of a variable while the execution goes on.</p>
|
515
|
+
<div class="code_container">
|
516
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
517
|
+
(rdb:1) display @recent_comments
|
518
|
+
1: @recent_comments =
|
519
|
+
</pre>
|
520
|
+
</div>
|
521
|
+
<p>The variables inside the displaying list will be printed with their values after you move in the stack. To stop displaying a variable use <tt>undisplay _n_</tt> where <em>n</em> is the variable number (1 in the last example).</p>
|
522
|
+
<h4 id="step-by-step">3.6 Step by Step</h4>
|
523
|
+
<p>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.</p>
|
524
|
+
<p>Use <tt>step</tt> (abbreviated <tt>s</tt>) to continue running your program until the next logical stopping point and return control to ruby-debug.</p>
|
525
|
+
<div class="info"><p>You can also use <tt>step</tt> <em>n</em><tt> and </tt>step- _n_+ to move forward or backward <em>n</em> steps respectively.</p></div>
|
526
|
+
<p>You may also use <tt>next</tt> 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 <em>n</em> steps.</p>
|
527
|
+
<p>The difference between <tt>next</tt> and <tt>step</tt> is that <tt>step</tt> stops at the next line of code executed, doing just a single step, while <tt>next</tt> moves to the next line without descending inside methods.</p>
|
528
|
+
<p>For example, consider this block of code with an included <tt>debugger</tt> statement:</p>
|
529
|
+
<div class="code_container">
|
530
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
531
|
+
class Author < ActiveRecord::Base
|
532
|
+
has_one :editorial
|
533
|
+
has_many :comments
|
534
|
+
|
535
|
+
def find_recent_comments(limit = 10)
|
536
|
+
debugger
|
537
|
+
@recent_comments ||= comments.where("created_at > ?", 1.week.ago).limit(limit)
|
538
|
+
end
|
539
|
+
end
|
540
|
+
</pre>
|
541
|
+
</div>
|
542
|
+
<div class="info"><p>You can use ruby-debug while using <tt>rails console</tt>. Just remember to <tt>require "ruby-debug"</tt> before calling the <tt>debugger</tt> method.</p></div>
|
543
|
+
<div class="code_container">
|
544
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
545
|
+
$ rails console
|
546
|
+
Loading development environment (Rails 3.1.0)
|
547
|
+
>> require "ruby-debug"
|
548
|
+
=> []
|
549
|
+
>> author = Author.first
|
550
|
+
=> #<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">
|
551
|
+
>> author.find_recent_comments
|
552
|
+
/PathTo/project/app/models/author.rb:11
|
553
|
+
)
|
554
|
+
</pre>
|
555
|
+
</div>
|
556
|
+
<p>With the code stopped, take a look around:</p>
|
557
|
+
<div class="code_container">
|
558
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
559
|
+
(rdb:1) list
|
560
|
+
[2, 9] in /PathTo/project/app/models/author.rb
|
561
|
+
2 has_one :editorial
|
562
|
+
3 has_many :comments
|
563
|
+
4
|
564
|
+
5 def find_recent_comments(limit = 10)
|
565
|
+
6 debugger
|
566
|
+
=> 7 @recent_comments ||= comments.where("created_at > ?", 1.week.ago).limit(limit)
|
567
|
+
8 end
|
568
|
+
9 end
|
569
|
+
</pre>
|
570
|
+
</div>
|
571
|
+
<p>You are at the end of the line, but… was this line executed? You can inspect the instance variables.</p>
|
572
|
+
<div class="code_container">
|
573
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
574
|
+
(rdb:1) var instance
|
575
|
+
@attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
|
576
|
+
@attributes_cache = {}
|
577
|
+
</pre>
|
578
|
+
</div>
|
579
|
+
<p><tt>@recent_comments</tt> hasn’t been defined yet, so it’s clear that this line hasn’t been executed yet. Use the <tt>next</tt> command to move on in the code:</p>
|
580
|
+
<div class="code_container">
|
581
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
582
|
+
(rdb:1) next
|
583
|
+
/PathTo/project/app/models/author.rb:12
|
584
|
+
@recent_comments
|
585
|
+
(rdb:1) var instance
|
586
|
+
@attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
|
587
|
+
@attributes_cache = {}
|
588
|
+
@comments = []
|
589
|
+
@recent_comments = []
|
590
|
+
</pre>
|
591
|
+
</div>
|
592
|
+
<p>Now you can see that the <tt>@comments</tt> relationship was loaded and @recent_comments defined because the line was executed.</p>
|
593
|
+
<p>If you want to go deeper into the stack trace you can move single <tt>steps</tt>, 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.</p>
|
594
|
+
<h4 id="breakpoints">3.7 Breakpoints</h4>
|
595
|
+
<p>A breakpoint makes your application stop whenever a certain point in the program is reached. The debugger shell is invoked in that line.</p>
|
596
|
+
<p>You can add breakpoints dynamically with the command <tt>break</tt> (or just <tt>b</tt>). There are 3 possible ways of adding breakpoints manually:</p>
|
597
|
+
<ul>
|
598
|
+
<li><tt>break line</tt>: set breakpoint in the <em>line</em> in the current source file.</li>
|
599
|
+
<li><tt>break file:line [if expression]</tt>: set breakpoint in the <em>line</em> number inside the <em>file</em>. If an <em>expression</em> is given it must evaluated to <em>true</em> to fire up the debugger.</li>
|
600
|
+
<li><tt>break class(.|\#)method [if expression]</tt>: set breakpoint in <em>method</em> (. and \# for class and instance method respectively) defined in <em>class</em>. The <em>expression</em> works the same way as with file:line.</li>
|
601
|
+
</ul>
|
602
|
+
<div class="code_container">
|
603
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
604
|
+
(rdb:5) break 10
|
605
|
+
Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10
|
606
|
+
</pre>
|
607
|
+
</div>
|
608
|
+
<p>Use <tt>info breakpoints _n_</tt> or <tt>info break _n_</tt> to list breakpoints. If you supply a number, it lists that breakpoint. Otherwise it lists all breakpoints.</p>
|
609
|
+
<div class="code_container">
|
610
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
611
|
+
(rdb:5) info breakpoints
|
612
|
+
Num Enb What
|
613
|
+
1 y at filters.rb:10
|
614
|
+
</pre>
|
615
|
+
</div>
|
616
|
+
<p>To delete breakpoints: use the command <tt>delete _n_</tt> to remove the breakpoint number <em>n</em>. If no number is specified, it deletes all breakpoints that are currently active..</p>
|
617
|
+
<div class="code_container">
|
618
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
619
|
+
(rdb:5) delete 1
|
620
|
+
(rdb:5) info breakpoints
|
621
|
+
No breakpoints.
|
622
|
+
</pre>
|
623
|
+
</div>
|
624
|
+
<p>You can also enable or disable breakpoints:</p>
|
625
|
+
<ul>
|
626
|
+
<li><tt>enable breakpoints</tt>: allow a list <em>breakpoints</em> or all of them if no list is specified, to stop your program. This is the default state when you create a breakpoint.</li>
|
627
|
+
<li><tt>disable breakpoints</tt>: the <em>breakpoints</em> will have no effect on your program.</li>
|
628
|
+
</ul>
|
629
|
+
<h4 id="catching-exceptions">3.8 Catching Exceptions</h4>
|
630
|
+
<p>The command <tt>catch exception-name</tt> (or just <tt>cat exception-name</tt>) can be used to intercept an exception of type <em>exception-name</em> when there would otherwise be is no handler for it.</p>
|
631
|
+
<p>To list all active catchpoints use <tt>catch</tt>.</p>
|
632
|
+
<h4 id="resuming-execution">3.9 Resuming Execution</h4>
|
633
|
+
<p>There are two ways to resume execution of an application that is stopped in the debugger:</p>
|
634
|
+
<ul>
|
635
|
+
<li><tt>continue</tt> [line-specification] (or <tt>c</tt>): 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.</li>
|
636
|
+
<li><tt>finish</tt> [frame-number] (or <tt>fin</tt>): 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.</li>
|
637
|
+
</ul>
|
638
|
+
<h4 id="editing">3.10 Editing</h4>
|
639
|
+
<p>Two commands allow you to open code from the debugger into an editor:</p>
|
640
|
+
<ul>
|
641
|
+
<li><tt>edit [file:line]</tt>: edit <em>file</em> using the editor specified by the <span class="caps">EDITOR</span> environment variable. A specific <em>line</em> can also be given.</li>
|
642
|
+
<li><tt>tmate _n_</tt> (abbreviated <tt>tm</tt>): open the current file in TextMate. It uses n-th frame if <em>n</em> is specified.</li>
|
643
|
+
</ul>
|
644
|
+
<h4 id="quitting">3.11 Quitting</h4>
|
645
|
+
<p>To exit the debugger, use the <tt>quit</tt> command (abbreviated <tt>q</tt>), or its alias <tt>exit</tt>.</p>
|
646
|
+
<p>A simple quit tries to terminate all threads in effect. Therefore your server will be stopped and you will have to start it again.</p>
|
647
|
+
<h4 id="settings">3.12 Settings</h4>
|
648
|
+
<p>There are some settings that can be configured in ruby-debug to make it easier to debug your code. Here are a few of the available options:</p>
|
649
|
+
<ul>
|
650
|
+
<li><tt>set reload</tt>: Reload source code when changed.</li>
|
651
|
+
<li><tt>set autolist</tt>: Execute <tt>list</tt> command on every breakpoint.</li>
|
652
|
+
<li><tt>set listsize _n_</tt>: Set number of source lines to list by default to <em>n</em>.</li>
|
653
|
+
<li><tt>set forcestep</tt>: Make sure the <tt>next</tt> and <tt>step</tt> commands always move to a new line</li>
|
654
|
+
</ul>
|
655
|
+
<p>You can see the full list by using <tt>help set</tt>. Use <tt>help set _subcommand_</tt> to learn about a particular <tt>set</tt> command.</p>
|
656
|
+
<div class="info"><p>You can include any number of these configuration lines inside a <tt>.rdebugrc</tt> file in your <span class="caps">HOME</span> directory. ruby-debug will read this file every time it is loaded and configure itself accordingly.</p></div>
|
657
|
+
<p>Here’s a good start for an <tt>.rdebugrc</tt>:</p>
|
658
|
+
<div class="code_container">
|
659
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
660
|
+
set autolist
|
661
|
+
set forcestep
|
662
|
+
set listsize 25
|
663
|
+
</pre>
|
664
|
+
</div>
|
665
|
+
<h3 id="debugging-memory-leaks">4 Debugging Memory Leaks</h3>
|
666
|
+
<p>A Ruby application (on Rails or not), can leak memory – either in the Ruby code or at the C code level.</p>
|
667
|
+
<p>In this section, you will learn how to find and fix such leaks by using tools such as BleakHouse and Valgrind.</p>
|
668
|
+
<h4 id="bleakhouse">4.1 BleakHouse</h4>
|
669
|
+
<p><a href="https://github.com/fauna/bleak_house/tree/master">BleakHouse</a> is a library for finding memory leaks.</p>
|
670
|
+
<p>If a Ruby object does not go out of scope, the Ruby Garbage Collector won’t sweep it since it is referenced somewhere. Leaks like this can grow slowly and your application will consume more and more memory, gradually affecting the overall system performance. This tool will help you find leaks on the Ruby heap.</p>
|
671
|
+
<p>To install it run:</p>
|
672
|
+
<div class="code_container">
|
673
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
674
|
+
$ sudo gem install bleak_house
|
675
|
+
</pre>
|
676
|
+
</div>
|
677
|
+
<p>Then setup your application for profiling. Then add the following at the bottom of config/environment.rb:</p>
|
678
|
+
<div class="code_container">
|
679
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
680
|
+
require 'bleak_house' if ENV['BLEAK_HOUSE']
|
681
|
+
</pre>
|
682
|
+
</div>
|
683
|
+
<p>Start a server instance with BleakHouse integration:</p>
|
684
|
+
<div class="code_container">
|
685
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
686
|
+
$ RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house rails server
|
687
|
+
</pre>
|
688
|
+
</div>
|
689
|
+
<p>Make sure to run a couple hundred requests to get better data samples, then press <tt>CTRL-C</tt>. The server will stop and Bleak House will produce a dumpfile in <tt>/tmp</tt>:</p>
|
690
|
+
<div class="code_container">
|
691
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
692
|
+
** BleakHouse: working...
|
693
|
+
** BleakHouse: complete
|
694
|
+
** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze.
|
695
|
+
</pre>
|
696
|
+
</div>
|
697
|
+
<p>To analyze it, just run the listed command. The top 20 leakiest lines will be listed:</p>
|
698
|
+
<div class="code_container">
|
699
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
700
|
+
191691 total objects
|
701
|
+
Final heap size 191691 filled, 220961 free
|
702
|
+
Displaying top 20 most common line/class pairs
|
703
|
+
89513 __null__:__null__:__node__
|
704
|
+
41438 __null__:__null__:String
|
705
|
+
2348 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:Array
|
706
|
+
1508 /opt/local//lib/ruby/gems/1.8/specifications/gettext-1.90.0.gemspec:14:String
|
707
|
+
1021 /opt/local//lib/ruby/gems/1.8/specifications/heel-0.2.0.gemspec:14:String
|
708
|
+
951 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:111:String
|
709
|
+
935 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:String
|
710
|
+
834 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:146:Array
|
711
|
+
...
|
712
|
+
</pre>
|
713
|
+
</div>
|
714
|
+
<p>This way you can find where your application is leaking memory and fix it.</p>
|
715
|
+
<p>If <a href="https://github.com/fauna/bleak_house/tree/master">BleakHouse</a> doesn’t report any heap growth but you still have memory growth, you might have a broken C extension, or real leak in the interpreter. In that case, try using Valgrind to investigate further.</p>
|
716
|
+
<h4 id="valgrind">4.2 Valgrind</h4>
|
717
|
+
<p><a href="http://valgrind.org/">Valgrind</a> is a Linux-only application for detecting C-based memory leaks and race conditions.</p>
|
718
|
+
<p>There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. For example, a C extension in the interpreter calls <tt>malloc()</tt> but is doesn’t properly call <tt>free()</tt>, this memory won’t be available until the app terminates.</p>
|
719
|
+
<p>For further information on how to install Valgrind and use with Ruby, refer to <a href="http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/">Valgrind and Ruby</a> by Evan Weaver.</p>
|
720
|
+
<h3 id="plugins-for-debugging">5 Plugins for Debugging</h3>
|
721
|
+
<p>There are some Rails plugins to help you to find errors and debug your application. Here is a list of useful plugins for debugging:</p>
|
722
|
+
<ul>
|
723
|
+
<li><a href="https://github.com/josevalim/rails-footnotes">Footnotes</a>: Every Rails page has footnotes that give request information and link back to your source via TextMate.</li>
|
724
|
+
<li><a href="https://github.com/ntalbott/query_trace/tree/master">Query Trace</a>: Adds query origin tracing to your logs.</li>
|
725
|
+
<li><a href="https://github.com/dan-manges/query_stats/tree/master">Query Stats</a>: A Rails plugin to track database queries.</li>
|
726
|
+
<li><a href="http://code.google.com/p/query-reviewer/">Query Reviewer</a>: This rails plugin not only runs “<span class="caps">EXPLAIN</span>” before each of your select queries in development, but provides a small <span class="caps">DIV</span> in the rendered output of each page with the summary of warnings for each query that it analyzed.</li>
|
727
|
+
<li><a href="https://github.com/smartinez87/exception_notification/tree/master">Exception Notifier</a>: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application.</li>
|
728
|
+
<li><a href="https://github.com/defunkt/exception_logger/tree/master">Exception Logger</a>: Logs your Rails exceptions in the database and provides a funky web interface to manage them.</li>
|
729
|
+
</ul>
|
730
|
+
<h3 id="references">6 References</h3>
|
731
|
+
<ul>
|
732
|
+
<li><a href="http://www.datanoise.com/ruby-debug">ruby-debug Homepage</a></li>
|
733
|
+
<li><a href="http://www.sitepoint.com/article/debug-rails-app-ruby-debug/">Article: Debugging a Rails application with ruby-debug</a></li>
|
734
|
+
<li><a href="http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/">ruby-debug Basics screencast</a></li>
|
735
|
+
<li><a href="http://railscasts.com/episodes/54-debugging-with-ruby-debug">Ryan Bate’s ruby-debug screencast</a></li>
|
736
|
+
<li><a href="http://railscasts.com/episodes/24-the-stack-trace">Ryan Bate’s stack trace screencast</a></li>
|
737
|
+
<li><a href="http://railscasts.com/episodes/56-the-logger">Ryan Bate’s logger screencast</a></li>
|
738
|
+
<li><a href="http://bashdb.sourceforge.net/ruby-debug.html">Debugging with ruby-debug</a></li>
|
739
|
+
<li><a href="http://cheat.errtheblog.com/s/rdebug/">ruby-debug cheat sheet</a></li>
|
740
|
+
<li><a href="http://wiki.rubyonrails.org/rails/pages/HowtoConfigureLogging">Ruby on Rails Wiki: How to Configure Logging</a></li>
|
741
|
+
<li><a href="http://blog.evanweaver.com/files/doc/fauna/bleak_house/files/README.html">Bleak House Documentation</a></li>
|
742
|
+
</ul>
|
743
|
+
|
744
|
+
<h3>Feedback</h3>
|
745
|
+
<p>
|
746
|
+
You're encouraged to help improve the quality of this guide.
|
747
|
+
</p>
|
748
|
+
<p>
|
749
|
+
If you see any typos or factual errors you are confident to
|
750
|
+
patch, please clone <a href="https://github.com/lifo/docrails">docrails</a>
|
751
|
+
and push the change yourself. That branch of Rails has public write access.
|
752
|
+
Commits are still reviewed, but that happens after you've submitted your
|
753
|
+
contribution. <a href="https://github.com/lifo/docrails">docrails</a> is
|
754
|
+
cross-merged with master periodically.
|
755
|
+
</p>
|
756
|
+
<p>
|
757
|
+
You may also find incomplete content, or stuff that is not up to date.
|
758
|
+
Please do add any missing documentation for master. Check the
|
759
|
+
<a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
|
760
|
+
for style and conventions.
|
761
|
+
</p>
|
762
|
+
<p>
|
763
|
+
If for whatever reason you spot something to fix but cannot patch it yourself, please
|
764
|
+
<a href="https://github.com/rails/rails/issues">open an issue</a>.
|
765
|
+
</p>
|
766
|
+
<p>And last but not least, any kind of discussion regarding Ruby on Rails
|
767
|
+
documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
|
768
|
+
</p>
|
769
|
+
</div>
|
770
|
+
</div>
|
771
|
+
</div>
|
772
|
+
|
773
|
+
<hr class="hide" />
|
774
|
+
<div id="footer">
|
775
|
+
<div class="wrapper">
|
776
|
+
<p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
|
777
|
+
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
|
778
|
+
</div>
|
779
|
+
</div>
|
780
|
+
|
781
|
+
<script type="text/javascript" src="javascripts/guides.js"></script>
|
782
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
|
783
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
|
784
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
|
785
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
786
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
787
|
+
<script type="text/javascript">
|
788
|
+
SyntaxHighlighter.all()
|
789
|
+
</script>
|
790
|
+
</body>
|
791
|
+
</html>
|