Sha256: 07c7d7c701614868a18955b9988c594c466756214b9c5644d82942a84bcee40d

Contents?: true

Size: 1.26 KB

Versions: 43

Compression:

Stored size: 1.26 KB

Contents

module ActionView
  module Helpers
    # Provides a set of methods for making it easier to debug Rails objects.
    module DebugHelper
      # Returns a YAML representation of +object+ wrapped with <pre> and </pre>.
      # If the object cannot be converted to YAML using +to_yaml+, +inspect+ will be called instead.
      # Useful for inspecting an object at the time of rendering.
      #
      # ==== Example
      #
      #   @user = User.new({ :username => 'testing', :password => 'xyz', :age => 42}) %>
      #   debug(@user)
      #   # =>
      #   <pre class='debug_dump'>--- !ruby/object:User
      #   attributes:
      #   &nbsp; updated_at:
      #   &nbsp; username: testing
      #
      #   &nbsp; age: 42
      #   &nbsp; password: xyz
      #   &nbsp; created_at:
      #   attributes_cache: {}
      #
      #   new_record: true
      #   </pre>

      def debug(object)
        begin
          Marshal::dump(object)
          "<pre class='debug_dump'>#{h(object.to_yaml).gsub("  ", "&nbsp; ")}</pre>"
        rescue Exception => e  # errors from Marshal or YAML
          # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
          "<code class='debug_dump'>#{h(object.inspect)}</code>"
        end
      end
    end
  end
end

Version data entries

43 entries across 40 versions & 10 rubygems

Version Path
actionpack_csi-2.3.5.p8 lib/action_view/helpers/debug_helper.rb
actionpack_csi-2.3.5.p7 lib/action_view/helpers/debug_helper.rb
actionpack_csi-2.3.5.p6 lib/action_view/helpers/debug_helper.rb
webroar-0.5.0 src/admin_panel/vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.2.4 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.2.2 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.2.1 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.2 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.1.9 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.1.8 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.1.7 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.1.6 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiantcms-couchrest_model-0.1.5 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
webroar-0.4.0 src/admin_panel/vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiant-0.8.2 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
radiant-0.9.0.rc2 vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
webroar-0.3.1 src/admin_panel/vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
webroar-0.3.0 src/admin_panel/vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/actionpack/pkg/actionpack-2.2.2/lib/action_view/helpers/debug_helper.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/actionpack/lib/action_view/helpers/debug_helper.rb