hellomello
hellomello

Reputation: 8597

JSON format display in Ruby on Rails

I've done PHP and was able to get JSON format to display nicely using

<pre></pre>

Now I'm trying to figure out how would you apply something similar with Ruby on Rails?

In my views document, I have this:

<%= @recent_media_items.to_json %>

Upvotes: 1

Views: 311

Answers (2)

Sancho.RubyROID
Sancho.RubyROID

Reputation: 121

I recommend trying CodeRay gem. It will do all the work for you. Just send to it your JSON and you'll get nice, colorized output:

html = CodeRay.scan("{\"Hello\":\"world!\"}", :json).div

or in your case

<%= CodeRay.scan(@recent_media_items.to_json, :json).div %>

Upvotes: 1

Logan Serman
Logan Serman

Reputation: 29880

<pre><%= @recent_media_items.to_json %></pre>

? <pre> is HTML, not PHP...

Upvotes: 5

Related Questions