RealityForge.org: Rails Plugin to Help Debug Views /articles/2006/03/20/rails-plugin-to-help-debug-views en-us 40 A little short for a storm trooper Rails Plugin to Help Debug Views <p>The debug_view_helper plugin was developed to make it easy to add debug information into your views. It was derived from techniques described in <a href="http://wiki.rubyonrails.com/rails/pages/HowtoDebugViews">HowtoDebugViews</a> and it makes it possible to expose the followng following debug data;</p> <ul> <li>Request Parameters</li> <li>Session Variables</li> <li>Flash Variables</li> <li>Assigned Template Variables</li> </ul> <p>Typically you add code such as the following to the bottom of your layout that exposes the debug button in development mode.</p> <div class="typocode"><pre><code class="typocode_ruby "><span class="punct">&lt;%</span> <span class="keyword">if</span> <span class="constant">RAILS_ENV</span> <span class="punct">==</span> <span class="punct">'</span><span class="string">development</span><span class="punct">'</span> <span class="punct">%&gt;</span><span class="string"> &lt;center</span><span class="punct">&gt;</span> <span class="punct">&lt;</span><span class="ident">button</span> <span class="ident">onclick</span><span class="punct">=&quot;</span><span class="string">show_debug_popup(); return false;</span><span class="punct">&quot;&gt;</span> <span class="constant">Show</span> <span class="ident">debug</span> <span class="ident">popup</span> <span class="punct">&lt;/</span><span class="regex">button&gt; &lt;</span><span class="punct">/</span><span class="ident">center</span><span class="punct">&gt;</span> <span class="punct">&lt;%=</span><span class="string"> debug_popup %&gt; &lt;% end %&gt;</span></code></pre></div> <p>You can grab the plugin from subversion at;</p> <p><a href="http://www.realityforge.org/svn/code/debug-view-helper/trunk/">http://www.realityforge.org/svn/code/debug-view-helper/trunk/</a></p> <p><b>Update:</b> Added the ability to add inline debug information via the following. Suggestion by John Dell.</p> <div class="typocode"><pre><code class="typocode_ruby "><span class="punct">&lt;%</span> <span class="keyword">if</span> <span class="constant">RAILS_ENV</span> <span class="punct">==</span> <span class="punct">'</span><span class="string">development</span><span class="punct">'</span> <span class="punct">%&gt;</span><span class="string"> &lt;%= debug_inline %</span><span class="punct">&gt;</span> <span class="punct">&lt;%</span> <span class="keyword">end</span> <span class="punct">%&gt;</span><span class="string"></span></code></pre></div> Mon, 20 Mar 2006 14:02:00 +1100 urn:uuid:3b08aded-4f0c-4955-9cdf-a39457c1a9aa Peter Donald http://www.realityforge.org/articles/2006/03/20/rails-plugin-to-help-debug-views Rails rails debug http://www.realityforge.org/articles/trackback/40 "Rails Plugin to Help Debug Views" by Jeremy Wohl <p>I couldn&#8217;t get this working in Rails 1.1, w/o the following patch. There&#8217;s probably a better way to do it.</p> <hr />x/view_debug_helper.rb 2006-03-31 13:34:38.000000000 -0800 <ins>+</ins> view_debug_helper.rb 2006-03-31 13:35:22.000000000 -0800 <code>@ -44,7 +44,7 </code>@ end end <p>- dump_vars(script,&#8217;Session Variables:&#8217;,@controller.instance_variable_get(&#8221;@data&#8221;)) + dump_vars(script,&#8217;Session Variables:&#8217;,@controller.instance_variable_get(&#8217;@session&#8217;).instance_variable_get(&#8221;@data&#8221;)) dump_vars(script,&#8217;Flash Variables:&#8217;,@controller.instance_variable_get(&#8221;@flash&#8221;)) dump_vars(script,&#8217;Assigned Template Variables:&#8217;,@controller.assigns) script &lt;&lt; add(&#8216;</table>&#8216;)</p> Sat, 01 Apr 2006 06:08:33 +1100 urn:uuid:b595819b-8ead-4d77-b8de-2099479f5f14 http://www.realityforge.org/articles/2006/03/20/rails-plugin-to-help-debug-views#comment-43 "Rails Plugin to Help Debug Views" by Violet <p>Thanks for pointing this out. I was not aware of this.</p> Mon, 20 Mar 2006 12:56:46 +1100 urn:uuid:b3656565-a4b9-4586-b9a6-f413e79a393a http://www.realityforge.org/articles/2006/03/20/rails-plugin-to-help-debug-views#comment-41