Platinum Partner

Rails Debug Popup - Makes Easy To Debug Info.


module DebugHelper
  
  def self.append_features(controller) #:nodoc:
    controller.ancestors.include?(ActionController::Base) ? controller.add_template_helper(self) : super
  end
    
  IGNORE = ["template_root", "template_class", "response", "template", "session", "url", "params", "subcategories", "ignore_missing_templates", "cookies", "request", "logger", "flash", "headers" ]

  
  def debug_popup

    popup_create do |script| 
      
      script << add( "Smarty Debug Console_#{@controller.class.name}" )

      script << add( "" )
      script << add( "" )
      
      script << add( "" )      
      @controller.assigns.each do |key, value|
          script << add ("")  unless IGNORE.include?(key)
      end unless  @controller.assigns.nil?


      script << add( "" )
      @controller.params.each do |key, value|
          script << add ("")  unless IGNORE.include?(key)          
      end unless  @controller.params.nil?


      script << add( "" )
      @controller.session.instance_variable_get("@data").each do |key, value|      
          script << add ("")  unless IGNORE.include?(key)          
      end unless  @controller.session.instance_variable_get("@data").nil?


      script << add( "" )
      @controller.instance_variable_get("@flash").each do |key, value|
          script << add ("")  unless IGNORE.include?(key)
      end unless @controller.instance_variable_get("@flash").nil?
        
    end
  
  end

  private
  
  def popup_create
    
    script = ""
  
  end
  
  
  def add(msg)
    "_rails_console.document.write(\"#{msg}\")\n"
  end  
  
  def dump_obj(object)
    begin
      Marshal::dump(object)
      "
#{h(object.to_yaml).gsub("  ", "  ").gsub("\n", "
\"+\n\"" )}
" rescue Object => e # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback "
#{h(object.inspect)}
" end end end I got this from EpiLog after seeing it mentioned on on the HowToDebugViews wiki. It is a helper class which will raise a Smarty like popup dumping all assigns, sessions, parameter and flash. Install it into your helper directory and include DebugHelper in your application controller. In your view (perhaps the bottom of your generic layout) add <%= debug_popup %>. Make sure to disable your popup blocker. This is especially useful if you work together with designers who have no idea what kind of information are exported by the controllers in a given view.
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}

Rails Debug Console
assigned template variables:
#{h key}#{dump_obj(value)}
request parameters:
#{h key}#{dump_obj(value)}
session variables:
#{h key}#{dump_obj(value)}
flash variables:
#{h key}#{dump_obj(value)}