I need a pretty output of the JSON for an activerecord object in the rails controller. Based on the answer to this question by jpatokal, I tried the following:
respond_to do |format|
format.json { render :json => JSON.pretty_generate(record) }
end
where
record
is an activerecord object. It does not produce a prettified output. However, when I try outputting a hash using the same code, viz,
respond_to do |format|
format.json { render :json => JSON.pretty_generate({"abc" => "1", "def" => "2"}) }
end
it does produce a prettified output (so pretty_generate is working, and so is my browser).
How do I use pretty_generate to produce a pretty output of an activerecord object?