嗨,我有一个表格,我想显示嵌套表格以添加问题并根据表格给出的答案更新比率星
<%= form_for @interview_round do |f| %>
<div class="modal-content">
<div class="row margin_0 margin_T10">
<h4 class="margin_T0 margin_B30 center-align">Interview Feedback Form</h4>
<div class="col s12 m12">
<div class=" interview_details_box">
<div class="row">
<div class="input-field col s12 m6">
<label for="intr_type" class="">Interview Type</label>
<%=h @interview_round.scheduled_at %>
</div>
<div class="input-field col s12 m6">
<select>
<option value="" selected>Choose your option</option>
<option value="1">Trainee</option>
<option value="2">Project Manager</option>
<option value="3">SSDE</option>
<option value="4">SDE</option>
</select>
<label for="intr_pos" class="">Position</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m6">
<input id="intr_candidate" type="text" class="validate" placeholder="Candidate" >
<label for="intr_candidate" class="">Candidate</label>
</div>
<div class="input-field col s12 m6">
<%= f.text_field :interviewer_name %>
<label for="intr_interviewer" class="">Interviewer</label>
</div>
</div>
<div class="row">
<div class=" col s12 m6 logical">
<label>Logical & Analytical Skills</label>
<div id="star-log" class="stars" > </div>
<%= f.text_field :log_skill, :id=>'hint-log' %>
</div>
<div class=" col s12 m6">
<label>Communication skills</label>
<div id="star-comm" class="stars" ></div>
<%= f.text_field :comm_skill, :id=>'hint-comm' %>
</div>
</div>
<div class="row">
<div class=" col s12 m6">
<label>Technical Skills</label>
<div id="star-tech" class="stars"></div>
<%= f.text_field :tech_skill, :id=>'hint-tech' %>
</div>
<div class="col s12 m6">
<label >Overall Rating</label>
<div id="star-overall"></div>
<%= f.text_field :overall_skill, :id=>'hint-overall' %>
</div>
</div>
<div class="row">
<div class="input-field col s12 m6">
<select>
<option value="" selected>Choose your option</option>
<option value="1">Recommended</option>
<option value="2">Not Recommended</option>
<option value="3">OnHold</option>
</select>
<label for="intr_result" class="">Result</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m12">
<%= f.text_area(:remarks, size: '50x10') %>
<label for="intr_remark">Remark</label>
</div>
<div class="row">
<%= f.fields_for :round_questions do |question| %>
<%= question.label :question %>
<%= question.text_field :question %>
<%= question.label :answer %>
<%= question.text_field :answer %>
<% end %>
</div>
</div>
</div>
</div>
</div>
<div class="row margin_0 margin_T10">
<div class="col s12 m12">
<div class="row margin_0 showdiv" style="display:none;">
<div class="col s12 m12">
<div class="input-field col s12 m12">
<input id="addques" type="text" class="validate" placeholder="Question" >
<label for="addques" class="">Question</label>
</div>
</div>
</div>
<div class="row margin_0 margin_T10">
<div class="col s12 center-align">
<button class="btn waves-effect waves-light btn-medium custom_btn_gray" type="button" name="action" onclick="$('.showdiv').toggle();">Add Question</button>
</div>
</div>
</div>
</div>
<div class="row margin_0 margin_T10">
<div class='col s12 center-align'>
<%= button_tag(:class => "btn waves-effect waves-light btn-large custom_btn_gray") do %>
Submit <i class="mdi-content-send right"></i>
<% end %>
</div>
</div>
<% end %>
</div>
我实际上是在 interview_rounds 控制器的编辑表单中使用它
嵌套形式的方法为
def edit
@interview_round = InterviewRound.where(id: params[:id]).first
3.times {@interview_round.round_questions.build}
respond_to do |format|
format.js
end
end
interview_rounds 模型
has_many :round_questions
accepts_nested_attributes_for :round_questions
和 round_question 模型
belongs_to :interview_round
评分系统实际上定义为,当用户对逻辑技能、沟通技能和技术技能(分数来自问答)进行评分时,会计算星级的平均值并将其存储在整体技能和此功能的 javascript 中给出为
$('#star-log').raty({
target : '#hint-log',
targetType : 'score',
targetKeep : true
});
$('#star-comm').raty({
target : '#hint-comm',
targetType : 'score',
targetKeep : true
});
$('#star-tech').raty({
target : '#hint-tech',
targetType : 'score',
targetKeep : true
});
$('#star-overall').raty({
target : '#hint-overall',
targetType : 'score',
targetKeep : true,
readOnly : true
});
$(document).on("click", ".stars", function(){
var score = 0 ;
//loop through stars to get score
$('.stars').each(function(i, obj) {
//if score is there will be undefined if star not selected
if ($(obj).raty('score'))
score += $(obj).raty('score');
});
//calculating average
score = score / $(".stars").length;
$('#star-overall').raty({score: score });
$("#hint-overall").val(score.toFixed(2));
});
现在功能定义为
表格上已经存在 3 个问题,并且会有一个添加更多可选问题的按钮(3 个问题是强制性的),当用户对问题进行评分时,这些问题的答案将是星级类型,分数将被计算并作为平均率存储在技术技能中(技术技能对整体技能的贡献)
请告诉我如何提供添加更多问题的选项,这些答案评分将被计算为平均水平并存储在技术技能中,我正在研究它一天但不知道该怎么做,提前谢谢