我正在构建一个数学运动应用程序。我想存储分成练习的问题,每个练习属于不同的部分。每个年级还有多个部分(总共12个等级)。
如何跟踪用户的回答(操作)?例如,当用户浏览应用程序时,决定从“Pre-K”等级的“G”部分的练习“G1”中回答问题7,并提供我想要跟踪的正确答案,并在将来向他提供统计数据关于他的表现。
目前我的用户模型与问题之间没有关联,我想听听其他人关于解决这个问题的最有效方法(也许现在的模型完全错误)
现在是has_many,belongs_to关系的模型图(我将稍后在问题模型中添加'the_question':string和'answer':字符串):
答案 0 :(得分: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
更合适。