我正在开发一个网站,将主办任何科目的不同测试。我使用嵌套表单进行引用。考试有问题,问题有4个选项,每个问题都有正确的答案。模型如下所示:
class Exam < ActiveRecord::Base
has_many :questions
validates :name, presence: true
accepts_nested_attributes_for :questions,
reject_if: proc {|attributes| attributes['content'].blank?},
allow_destroy: true
end
class Question < ActiveRecord::Base
belongs_to :exam
has_many :correct_answers
validates :content, presence: true
has_many :options
accepts_nested_attributes_for :options,
reject_if: proc {|attributes| attributes['content'].blank?},
allow_destroy: true
accepts_nested_attributes_for :correct_answers, reject_if: proc {|attributes| attributes['content'].blank?},
allow_destroy: true
end
class Option < ActiveRecord::Base
belongs_to :question
end现在我不能理解如何创建一个web表单,可以提交结果,并可以比较选择与正确的答案,然后呈现视图与正确的答案和选择的答案。
请帮帮忙。
发布于 2016-11-07 04:57:27
我想你可以使用一些简单的东西,比如:
<%= form_for(@exam) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :question %>
<%= f.text_field :question%>
<%= f.submit Submit %>仅供参考,如果您需要有关form -> https://www.launchacademy.com/codecabulary/learn-rails/writing-forms的任何进一步帮助,请阅读本文
https://stackoverflow.com/questions/40450915
复制相似问题