Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8411149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:22:06+00:00 2026-06-10T00:22:06+00:00

I know I’m close, but I’m stuck. These are the three models I’m working

  • 0

I know I’m close, but I’m stuck.

These are the three models I’m working with: AttendanceSheet, Attendance and Child.

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

So the join model is Attendance. I’m trying to create an attendance sheet with a list of all students from a particular course and then use a checkbox to mark if they attended or not. Like this…

Attendance Sheet
Course: Biology
Date: _____________

Michael Scott   [] Notes: sick
Jim Halpert     [] Notes: ____
Dwight Schrute  [] Notes: ____

So the attendances tables has the following columns:

child_id
attended (boolean) to check if the student attended course or not
notes

The part I’m having trouble with is coming up with some kind of loop to display all the students that belongs to that class and having fields for attended and notes for each of them.

This is what I have…

_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 %>

attendance_sheets_controller.rb

def new
  @attendance_sheet = AttendanceSheet.new
  @course = Course.find(params[:course_id])

  respond_to do |format|
    format.html
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:22:07+00:00Added an answer on June 10, 2026 at 12:22 am

    Using rails accepts_nested_attributes_for :attendances, you can do something like this in your controller:

    def new
      @attendance_sheet = AttendanceSheet.new
      @course = Course.find(params[:course_id])
      @course.children.each do |c|
        @attendance_sheet.attendances << Attendance.new(:child => c)
      end
    
      respond_to do |format|
        format.html
      end
    end
    

    Then do something like this in your simple_form_for @attendance_sheet

    <%= f.fields_for :attendances do |att| %>
      <%= att.check_box :child, :label => att.object.child.full_name %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Know this might be rather basic, but I been trying to figure out how
I know you can not set a key value dynamically, but what about the
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
i know this is a stupid question but i d'ont know how to do
I know this is a stupid question, but I've looked for 45 mins now
I know that design patterns is generally something that's connected to OO programming, but
I know very little about Agile but I wonder if there is any difference
I know there are similar questions already on SO but none of them seem
I know regex and substrings is a common question on here but i can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.