私は近くにいることを知っていますが、立ち往生しています。
私が使用しているモデルは、AttendanceSheet、Attendance、Child の 3 つです。
AttendanceSheet
has_many :attendances, :dependent => :destroy
accepts_nested_attributes_for :attendances
belongs_to :course
Child
has_many :attendances
Attendance
belongs_to :attendance_sheet
belongs_to :child
したがって、参加モデルは出席です。特定のコースのすべての学生のリストを含む出席シートを作成し、チェックボックスを使用して出席したかどうかをマークしようとしています。このような...
Attendance Sheet
Course: Biology
Date: _____________
Michael Scott [] Notes: sick
Jim Halpert [] Notes: ____
Dwight Schrute [] Notes: ____
したがって、出席テーブルには次の列があります。
child_id
attended (boolean) to check if the student attended course or not
notes
私が問題を抱えている部分は、そのクラスに属するすべての学生を表示し、出席するためのフィールドとそれぞれのメモを持つ何らかのループを考え出すことです。
これは私が持っているものです...
_form.html.erb
<%= simple_form_for @attendance_sheet, :html => { :class => 'form-horizontal' } do |f| %>
<h2>Course: <%= @course.name %></h2>
<div class="form-inputs">
<%= f.input :attendance_on, :as => :string, :hint => 'YYYY-MM-DD', :input_html => {:class => :datepicker, :value => Date.today} %>
</div>
<% @course.children.each do |child| %>
*** trouble here ***
<%= check_box_tag %> <%= child.full_name %><br />
<% end %>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
Attention_sheets_controller.rb
def new
@attendance_sheet = AttendanceSheet.new
@course = Course.find(params[:course_id])
respond_to do |format|
format.html
end
end