Ruby on rails 关联在序列化程序中不起作用

Ruby on rails 关联在序列化程序中不起作用,ruby-on-rails,ruby,ruby-on-rails-4,serialization,associations,Ruby On Rails,Ruby,Ruby On Rails 4,Serialization,Associations,所以我有两张表,一个问题有很多答案。我构建了一个序列化程序来显示以下问题的答案: 问题序列化程序: class QuestionSerializer < ActiveModel::Serializer attributes :id, :name, :question_type, :is_deleted, :is_editable, :sort, :max_character, :min_character, :weighting, :required_lang

所以我有两张表,一个问题有很多答案。我构建了一个序列化程序来显示以下问题的答案:

问题序列化程序:

class QuestionSerializer < ActiveModel::Serializer
  attributes :id, :name, :question_type, :is_deleted, :is_editable, :sort, :max_character,
             :min_character, :weighting, :required_languages

  has_many :answers, serializer: AnswerSerializer

  def name
    { en: object.name_en, fr: object.name_fr, es: object.name_es }
  end
class AnswerSerializer < ActiveModel::Serializer
  attributes :text, :order, :answerId

  def answerId
    object.id
  end

  def text
    { en: object.text_en, fr: object.text_fr, es: object.text_es }
  end
end
答案模式:

class Answer < ActiveRecord::Base
  # Belongs_to associations
  belongs_to :questions
  belongs_to :join_answers_forms_questions
end
class-Answer

有人知道会发生什么吗?

在问题序列化程序的属性中,在
:required\u languages
后面有一个逗号。你的代码里有逗号吗?如果是,请将其删除,看看是否有帮助。@moveson很遗憾,代码中不再有它,因此这不是问题所在:(能否显示调用序列化程序的控制器?在QuestionSerializer的属性中,
:required\u languages
,后面有一个逗号。该逗号是否确实存在于代码中?如果存在,请删除它,看看是否有帮助。@moveson很遗憾,它不再存在于代码中,因此这不是问题:(您能展示一下调用序列化程序的控制器吗?
class Answer < ActiveRecord::Base
  # Belongs_to associations
  belongs_to :questions
  belongs_to :join_answers_forms_questions
end