I am trying to create a simple form for a student to select list of courses and enter remarks for each of the course
these are the associations I have in student model
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content">
<input type="hidden" value="ABC123" class="imgRef">
<div class="input-group">
<input type="text" class="form-control" id="Item1" placeholder="description" value="" name="Item1" required>
<button class="btn btn-default btn-fill addField">
BUTTON
</button>
</div>
</div>
I have to create a form using rails 4 simple form that lists out all courses as check boxes and text field next to each check-box to fill in remarks for that course. I am able to generate the checkboxes fine but not sure how to create textbox next to each course..below is what I have..
has_many :course_associations
has_many :courses, :through=> :course_associations
accepts_nested_attributes_for :course_associations
accepts_nested_attributes_for :courses
答案 0 :(得分: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
。