0
votes

I am trying to create a simple form for a student to select list of courses and enter remarks for each of the course

  1. course is a lookup table with name field
  2. student with name field etc..
  3. association table with course id, student-id,remarks

these are the associations I have in student model has_many :course_associations has_many :courses, :through=> :course_associations accepts_nested_attributes_for :course_associations accepts_nested_attributes_for :courses

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..

<% 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
I really don't know enough about what is happening to answer this question. When you say it "Doesn't work" what do you mean? Is there an error? Is something not rendering as you expected? Also, for that matter, what is "this thing?" Give us some more info!neanderslob
@neanderslob please see the edited question. for each course I need to create text box for the extra field in course association table ..strutsnew

1 Answers

0
votes

If I'm understanding correctly I would add simple_fields_for to your form where you have need to create text box for extra field in course association like so.

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

Make sure to update your strong params and I believe the above should accomplish what you're after.

If it doesn't work, I'm probably not understanding how your form is set up and would need to see the whole thing out to simple_form_for.