Ruby on rails 使用Rails在JBuilder中嵌套关联

Ruby on rails 使用Rails在JBuilder中嵌套关联,ruby-on-rails,json,ruby-on-rails-4,jbuilder,Ruby On Rails,Json,Ruby On Rails 4,Jbuilder,我有以下json jbuilder: json.question_cluster @question_cluster json.questions @question_cluster.questions do |question| json.id question.id json.title question.title json.required question.required json.has_other question.has_other json.positi

我有以下json jbuilder:

json.question_cluster @question_cluster

json.questions @question_cluster.questions do |question|
  json.id question.id
  json.title question.title
  json.required question.required
  json.has_other question.has_other
  json.position question.position
  json.options question.options do |option|
    json.id option.id
    json.label option.label
    json.value option.value
    json.position option.position
    json.go_page option.go_page
  end
end
这将在我的应用程序中生成以下响应:

问题是我想把问题放入
question\u cluster
,但是
@question\u cluster
是一个单一的对象,所以我不能使用do end(它会抛出一个错误),在这种情况下我能做什么?

您尝试过这种方法吗

json.question_cluster do
  json.(@question_cluster)
  json.questions @question_cluster.questions do |question|
    json.id question.id
    json.title question.title
    json.required question.required
    json.has_other question.has_other
    json.position question.position
    json.options question.options do |option|
      json.id option.id
      json.label option.label
      json.value option.value
      json.position option.position
      json.go_page option.go_page
    end
  end
end
你试过这样吗

json.question_cluster do
  json.(@question_cluster)
  json.questions @question_cluster.questions do |question|
    json.id question.id
    json.title question.title
    json.required question.required
    json.has_other question.has_other
    json.position question.position
    json.options question.options do |option|
      json.id option.id
      json.label option.label
      json.value option.value
      json.position option.position
      json.go_page option.go_page
    end
  end
end