Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd recommend using <code>yajl-ruby</code>'s API directly instead of the JSON gem compatibility API mainly for the reason that the JSON gem's <code>to_json</code> method conflict with <code>ActiveSupport</code> and has had long-standing issues making them work together.</p> <p>If you just do <code>config.gem 'yajl-ruby', :lib =&gt; 'yajl'</code> instead, you'll need to use <code>Yajl::Parser</code> and <code>Yajl::Encoder</code> directly to parse/encode objects. The advantage of this is you'll be certain there won't be any conflicts with method overrides and as such, be guaranteed your JSON encoding/parsing code will work as expected. The disadvantage is if you're using any gems that use the JSON gem, they'll continue to do so but you're own code will use yajl-ruby.</p> <p>If you wanted to, you could use your config.gem line, then in an initializer <code>require 'yajl'</code> so you'd have both API's loaded. The <code>yajl/json_gem</code> include will override anything that's using the JSON gem with <code>yajl</code> - to ensure this overrides those methods try to make sure <code>require 'yajl/json_gem'</code> happens last.</p> <p>If you're using Rails 3, you can add this to an initializer:</p> <pre><code>ActionController::Renderers.add :json do |json, options| json = Yajl.dump(json) unless json.respond_to?(:to_str) json = "#{options[:callback]}(#{json})" unless options[:callback].blank? self.content_type ||= Mime::JSON self.response_body = json end </code></pre> <p>To make sure <code>render :json =&gt; ...</code> calls use <code>yajl-ruby</code> as well.</p> <p>Sorry if this isn't really answering your question but I wanted to at least give the suggestion of using <code>yajl-ruby</code>'s API directly :)</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