0

我正在构建一个数学练习应用程序。我想存储分成练习的问题,每个练习属于不同的部分。每个年级也有多个部分(总共 12 个年级)。

我如何跟踪用户的回答(操作)?例如,当用户浏览应用程序时,决定回答“Pre-K”年级“G”部分的练习“G1”中的问题 7,并提供我想要跟踪的正确答案,并在将来为他提供统计数据关于他的表现。

目前我的用户模型与问题之间没有联系,我想听听其他人关于解决这个问题的最有效方法(也许现在的模型完全错误)

这是现在具有 has_many、belongs_to 关系的模型图(稍后我将添加 'the_question':string 和 'answer':string 到问题模型中): 在此处输入图像描述

4

1 回答 1

1

我认为所缺少的只是一个Answer模型,它与用户相关联。

或者,您也可以在“父母”上定义关系Question

class Grade < ActiveRecord::Base
  has_many :users, :through => :sections # optional. i.e. 'users that have answers in this grade'
end

class Section < ActiveRecord::Base
  has_many :users, :through => :exercises # optional
end

class Exercise < ActiveRecord::Base
  has_many :users, :through => :questions # optional
end

class Question < ActiveRecord::Base
  has_many :answers
  has_many :users, :through => :answers # optional
end

class Answer < ActiveRecord::Base
  belongs_to :question
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :answers
end

更新:重新阅读您的描述,我认为CorrectAnswer会比Answer.

于 2012-10-25T01:23:12.930 回答