jbuilder

https://github.com/rails/jbuilder

Ruby

Jbuilder: generate JSON objects with a Builder-style DSL

JbuilderTemplate#cache_if!

Conditionally caches the json depending in the condition given as first parameter. Has the same
signature as the `cache` helper method in `ActionView::Helpers::CacheHelper` and so can be used in
the same way.

Example:

  json.cache_if! !admin?, @person, expires_in: 10.minutes do
    json.extract! @person, :name, :age
  end

Source | Google | Stack overflow

Edit

git clone [email protected]:rails/jbuilder.git

cd jbuilder

open lib/jbuilder/jbuilder_template.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-JbuilderTemplate-cache_if--for-pr


# Commit to git

git add lib/jbuilder/jbuilder_template.rbgit commit -m "better docs for JbuilderTemplate#cache_if!"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-JbuilderTemplate-cache_if--for-pr

hub pull-request


# Celebrate!