2013-08-18 63 views
0

我有一个表单,它遍历每个学生,并根据使用单选按钮的目标对它们进行评估。每个目标的得分应为1-5。此刻,除了单选按钮,一切都可以正常工作 - 在整个表格中,一次只能选择一个单选按钮 - 也就是说,如果目标一被标记为3,则目标二被标记为4,目标一变得没有标记。只有一个单选按钮可以点击整个表格

代码如下:

evaluation

evaluations - new.html.erb

... 
<div class="holder2 round clear"> 
    <%= form_for([@student, @evaluation]) do |f| %> 
     <% @subjects.each do |group, subjects| %> 
     <% subjects.each do |subject| %> 
      <h3><%= subject.name %></h3> 
      <%= render "goal_eval", :subject => subject, :f => f %> 
     <% end %> 
     <% end %> 
     <%= f.submit "Next student", :class => 'big_button round unselectable' %> 
    <% end %> 
</div> 

goal_eval partial

<table class="fixed"> 
    <tbody> 
     <% subject.goals.each do |goal| %> 
     <tr class="<%= cycle("odd", "even", name: "goals")%>"> 
     <td class="goal_row"><%= goal.goal %></td> 
     <td> 
      <% [1, 2, 3, 4, 5].each do |score| %> 
      <%= radio_button_tag :score, score, goal_id: goal.id, student_id: @student.id %> 
      <%= score %> 
      <% end %> 
     </td> 
     </tr> 
    <% end %> 
     <% reset_cycle("goals") %> 
    </tbody> 
</table> 

回答

1

每个radio_button_tag具有相同的名称。

您可以为每个按钮命名score_xx,其中xx是目标的ID。

<%= radio_button_tag "score_#{goal.id}", score, goal_id: goal.id, student_id: @student.id %> 
+0

是完美工作,欢呼声 - 我不得不改变它'比分_#{goal.id}',因为subject_id是所有三个目标相同: '<%= radio_button_tag“比分_#{ goal.id}“,得分,goal_id:goal.id,student_id:@ student.id%>' – dax

+0

是的,我的不好,编辑答案。很高兴工作! – Intrepidd

0

因为他们都在同一个相同名称/ ID,您需要范围嵌套表格与fields_for帮手。

猜猜你的prtial电话和ff.fields_for goal围绕你的tr每个循环应该做的伎俩添加一个f.fields_for subject do |ff|

相关问题