charliesome/better_errors — pull request #117 by KL-7 (2013-02-05 11:52:07+00:00)
Title: Pretty print params and Rack session.

This pull request aims to close #75 and changes request parameters and Rack session formatting from this:

![before](https://f.cloud.github.com/assets/270365/127169/13ece880-6f89-11e2-96ba-5c5168670930.png)

to this:

![after](https://f.cloud.github.com/assets/270365/127171/192d1b4e-6f89-11e2-88b1-23dd836852f0.png)

I encountered a problem with generating nicely indented JSON from a `HashWithIndifferentAccess`: while `JSON.pretty_generate` produces properly indented representation of `Hash` objects, it refuses to do the same thing for instances of `Hash` subclasses and produces no indentation whatsoever:

```ruby
1.9.3-p374 :001 > class A < Hash; end
=> nil
1.9.3-p374 :002 > hash = { :foo => 3 }
=> {:foo=>3}
1.9.3-p374 :003 > hash_like = A.new.merge!(hash)
=> {:foo=>3}
1.9.3-p374 :004 > require 'json'
=> true
1.9.3-p374 :005 > JSON.pretty
JSON.pretty_generate JSON.pretty_unparse
1.9.3-p374 :005 > JSON.pretty_generate(hash)
=> "{\n \"foo\": 3\n}"
1.9.3-p374 :006 > JSON.pretty_generate(hash_like)
=> "{\n \"foo\": 3\n}"
1.9.3-p374 :008 > require 'active_support/json'
=> true
1.9.3-p374 :009 > JSON.pretty_generate(hash)
=> "{\n \"foo\": 3\n}"
1.9.3-p374 :010 > JSON.pretty_generate(hash_like)
=> "{\"foo\":3}"
```

As you can see, it happens only when you have `active_support/json` required (that is obviously true for a regular Rails application), so the cause of the issue must be somewhere there, but I didn't manage to track down it further.

As a workaround, I convert every `Hash`-like object to a regular `Hash` object using custom `purify_hash` method. I'd be happy if someone could suggest a better solution.