Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Rails Debug Popup - Makes Easy To Debug Info.

DZone's Guide to

Rails Debug Popup - Makes Easy To Debug Info.

·
Free Resource

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( "
#{h(object.to_yaml).gsub("  ", "  ").gsub("\n", "
\"+\n\"" )}
#{h(object.inspect)}
EpiLogHowToDebugViews <%= debug_popup %> " ) 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) "" rescue Object => e # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback "" end end end I got this from after seeing it mentioned on on the 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 . 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.
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)}
Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}