Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update</strong> <em>This fix is only applicable to Rails &lt; 2.3. As Giles mentions below, they fixed this in 2.3 internally using much the same technique. But beware the json gem's earlier attempt at Rails compatibility</em> (<code>json/add/rails</code>), <em>which, if required explicitly will break everything all over again.</em></p> <p>Do you mean the <code>require 'json'</code> statement itself raises that Exception? Or do you mean when you call <code>@something.to_json(:something =&gt; value)</code> you get the error? The latter is what I would expect, if you have a problem requiring the JSON gem then I'm not sure what's going on.</p> <p>I just ran into this problem with the oauth gem. In my case, there is not a true conflict, because the oauth gem doesn't depend on <code>to_json</code> implementation. Therefore the problem is that JSON is clobbering the ActiveSupport declarations. I solved this by simply requiring json before ActiveSupport is loaded. Putting</p> <pre><code>require 'json' </code></pre> <p>inside the <code>Rails::Initializer</code> did the trick (though putting it after the block did NOT).</p> <p>That allows ActiveSupport to clobber the default JSON implementation instead.</p> <p>Now if you are using a gem that actually depends on the JSON implementation of <code>to_json</code> then you are up a creek. This is definitely the worst of meta-programming, and I would advocate for the Rails and JSON gem developers to resolve the conflict, though it will be painful because one or the other will have to break backwards compatibility.</p> <p>In the short term, gem authors may be able to bridge the gap by supporting both implementations. This is more or less feasible depending on how the gem uses the method. A worst case scenario is an official fork (ie. <code>gem</code> and <code>gem-rails</code>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload