2016-02-12 92 views
0

我试图创建一个简单的形式为学生选择的课程列表和每个过程轨道4创建在关联表的额外领域

  1. 当然进入的言论形式与名称的查找表现场
  2. 学生与名字段等。与课程ID,学生ID
  3. 关联表,备注

这些都是我在学生模型的关联 has_many :course_associations has_many :courses, :through=> :course_associations accepts_nested_attributes_for :course_associations accepts_nested_attributes_for :courses

我必须使用rails 4简单表单创建一个表单,将所有课程列为复选框和每个复选框旁边的文本字段以填写该课程的备注。我能够产生的复选框不错,但不知道如何创建旁边的每个course..below文本框是我..

<% Course.all.each do |course| %> 
       <div class="col-lg-5 col-md-5"> 
        <%= check_box_tag "student[course_ids][]", course.id, 
            course.id.in?(@student.course_ids), 
            { 
             id: "student_course_ids_" + course.id.to_s 
            }%> 
        <%= label(:student, "course_ids_" + course.id.to_s, course.name) %> 
        **need to create text box for extra field in course association** 
       </div> 
       <%end%> 
+1

我真的不知道发生了什么事以回答这个问题。当你说它“不起作用”时,你的意思是什么?有错误吗?有没有像你期望的那样渲染?另外,就此而言,什么是“这件事?”给我们更多的信息! – neanderslob

+0

@neanderslob请参阅编辑的问题。对于每门课程,我需要为课程关联表中的额外字段创建文本框。 – strutsnew

回答

0

如果我理解正确我想补充simple_fields_for到您的表单,你有如此need to create text box for extra field in course association

<%= course.simple_fields_for :course_associations do |association| 
    <%= association.input :remarks(or whatever you've called it) %> 
<% end %> 

请确保更新您的强参数,我相信上面应该完成你以后的事情。

如果它不起作用,我可能不了解您的表单是如何设置的,并且需要将整个事件看成simple_form_for