5

I have a list of objects, tests, which contain questions and bonus questions, each of which has a subject model. I'm trying to include all of them in a JSON API but I keep getting odd incomprehensible syntax error messages. I can get it working with questions and subject or bonus questions and subjects, but not both. Here is what I have now:

render json: tests.as_json(:include => {:questions =>{:include => {:subject}},:bonuses => {:include => {:subject}}})

The error message I get is

/app/controllers/test_controller.rb:49: syntax error, unexpected '}', expecting => ...ssups =>{:include => {:subject}},:bonuses => {:include => {:... ... ^ /app/controllers/question_set_controller.rb:49: syntax error, unexpected '}', expecting => ...uses => {:include => {:subject}}}) ... ^ /app/controllers/question_set_controller.rb:76: syntax error, unexpected end-of-input, expecting keyword_end

Thanks in advance.

1 Answer 1

13

You have extra pair of braces wrapping a single symbol. That is not valid Ruby hash syntax. It should be

render json: tests.as_json(:include => {:questions => {:include => :subject}, :bonuses => {:include => :subject}})
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, I'm new to Ruby so I've been making a lot of these stupid syntax mistakes.

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.