1

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 %>

2 Answers 2

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

oh duh! haha that makes sense. I did try that, but its outputting it weird. its widening my page very extensively and near the end of scrolling right, there's only bits of json, and its not even formatted properly? Am I missing something?
1

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 %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.