Ask A Question


You’re not receiving notifications from this thread.

How do I create an attendance form for student attendance?

Ernesto Gutierrez asked in General

I've been racking my brain and just need to ask for help on the creating this function in my app.

Scope: simple app for non-profit for tracking student attendance
What I've done:

  • created the app
  • shared the app with the end people
  • received positive feedback

What's missing for them is the ability to record attenance for multiple students at once. Without this they can not see the benefit of using this and I'm stuck maitaining an google sheet spreadsheet for them.

This (from what I've read) should be done in two steps:
Step 1 - record the date/time of the attendance for multiple students
Step 2 - record the hours / record you want to track for those that are present

  • a dozen more

Form 1 - mark students attendnace
for now I'm just sticking with checkboxes but i'm sure I'll move to something more dynamic with java script or something else but for now let's keep it simple.

From 2 - mark hours / record for present students
I'm getting fancy I know but the idea would be select all / select one / select a few and record hours for each student.


class Student <ActiveRecord::Base
    has_many :attendances, dependent: :destroy
    validates :first_name, :last_name, :school_grade, :team_name, :presence => true
class Attendance < ActiveRecord::Base
    belongs_to :student
    has_many :attendance_records
class Records <ActiveRecord::Base
    belongs_to :attendance
    belongs_to :student through: :attendance

I work on this in the evenings after my kids go to sleep so any help will significantly help reduce my :coffee: intake to normal healthy levels.


Redirected this question to the Slack Group got this response:

class AttendancesController < ApplicationController
  def mark
    @students = Student.where(id: params[:student_ids])

    ActiveRecord::Base.transaction do
      @students.each do |student|
        attendence = student.attendences.create(date: attendence_params[:date])


  def attendence_params
class AttendancesController < ApplicationController
  def mark
    @attendance_day = AttendanceDay.find(params[:attendance_day_id])
    @attendance_day.student_ids = params[:student_ids]

I'm a visual learner so having this to refer back to actually helped me understand how I can take an array like student_ids collected from a form and have the controller irreate on them to create in my case an attendance record. Currently there's a has_many / belongs_to association between the students & attendances model.

With the reponses I may end up uisng a joiner model to bridge Students & Attendnances with a has_many, through this way the end result would be:

class Student < ApplicationRecord
  has_many :attendances
    has_many :records, :through => :attendances
class Attendance < ApplicationRecord
  belongs_to :record
    belongs_to :student
class Record < ApplicationRecord
  has_many :attendances
    has_many :students, :through => :attendances

Can you share the git repo of your app, I can have a look

Using** cocoon** gem and some styling, you can mass mark student attendance (statuses in my case).
schedulable gem - good for scheduling & persisting events in the database
Screenshof from my app:


Nested forms make sense to me in theory but in practice I can't seem to see the implementation of it in an attendance tracker.
Here's the repo:

Here's a quick view of what I'm shooting for:

What I'm trying to do is setup an attendance app similar to
I'm not trying to clone it 1for1 but I'm trying to match the abilty to select multiple students from a list / table and mark them as [present, absent, excused, other]. Once they are marked with an attendance only those present are visible to take the next action mark hours of participation.

The part I've been stuck on is the select multiple and assign an attendance type. If you read from the top post I've been looking into this but can't seem to get it right.

The last 2 suggestions had me to the following to the AttendancesController

def mark_student #this is the most recnet attempt

    @students = Array(params[:student_ids].split(",")
    @students.each do |s|
     student = Student.find(s)!

    # @students = params[:student_ids].split(",") #this was the second suggestion
    # @students.each do |s|
    #  student = Student.find(s)
    #  student.attendances.create
    # end

    redirect_to attendances_url


HI, i am really happy to find your question and what you seek to accomplish as I am trying to build an add-on to my non-profits app for the exact same purpose. Where you able to solve and if so, do you mind sharing?

I work in a private bilingual school - Spanish/Italian teacher (it's my first academic year as a teacher and I'm also pursuing a Ph.D. degree at Max Planck Institute) and I need to track my class attendance. How can I track class attendance with the possibility to create attendance for all users so that I could see all students' names and an attendance field for each student at once? I would like to see all users on the list view and all options of the attendance.


Excellent share


Glad to see this awesome discussion! Thanks all



Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 84,111+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.