Search code examples
ruby-on-railsjbuilder

how to use jbuilder with yajl


I am using jbuilder to render JSON in Rails. However, I would like to use Faster JSON backend, as stated in jbuilder's GitHub. How can I use it? Is it just config in Application.rb?

require 'multi_json'
MultiJson.use :yawl

Solution

  • To integrate yajil-ruby you have to follow the bellow steps

    Note : These steps are tested in rails 4.2.3

    1) Add gem 'yajl-ruby', require: 'yajl' to Gemfile

    2) rub bundle install

    3) now check default json renderer is changed to yajl by enter this command in rails console MultiJson.engine then you should see the below result

    $ rails console
    Loading development environment (Rails 4.2.1)
    1.8.7 :001 > MultiJson.engine
     => MultiJson::Adapters::Yajl < MultiJson::Adapter 
    

    Thats it , now your default renderer is yajl