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.
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}})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With