2

In my controller I have a 'show' action and inside of it is an instance variable like:

@resume = Resume.find(params[:id])

It grabs the appropriate information from the database and displays that specific resume on the "show" page.

One of the fields is a string called "content" with a json object inside.

I want to know how to turn that @resume.content from a json string into an object so I can loop through it on the show page template.

Sorry if this question was not constructed properly, please ask if you need further explanation.

1
  • Can you post the actual value inside the content attribute? And also the string that's returned when you do content.to_json? Commented Oct 12, 2013 at 4:11

2 Answers 2

4

Have you tried @resume.content.to_json ?

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

2 Comments

based on the fact that they have a show action in their resume controller, I think it's safe to say they are using rails
Ok I just tried that and it's converting it into a json string so i set it to a variable and tried parsing the variable. This is currently what's in my resumes/show action -> (at)resume = Resume.find(params[:id]) str = (at)resume.content.to_json (at)resumeContent = JSON.parse(str)
4

To parse a string to Ruby object

JSON.parse @resume.content 

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.