Ernesto Gutierrez

Joined

1,400 Experience
6 Lessons Completed
1 Question Solved

Activity

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:
https://github.com/ernestozgutierrez/squashup/tree/models

Here's a quick view of what I'm shooting for: https://goo.gl/V8Jbgy

What I'm trying to do is setup an attendance app similar to https://www.classdojo.com/
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)
     student.attendances.build!
    end

    # @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

  end
    ```

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])
      end
    end
  end

  private

  def attendence_params
    params.require(:attendence).permit(:date)
  end
end
class AttendancesController < ApplicationController
  def mark
    @attendance_day = AttendanceDay.find(params[:attendance_day_id])
    @attendance_day.student_ids = params[:student_ids]
    @attendance_day.save
  end
end

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.

Suggestions:
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
end
class Attendance < ApplicationRecord
  belongs_to :record
    belongs_to :student
end
class Record < ApplicationRecord
  has_many :attendances
    has_many :students, :through => :attendances
end

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
https://stackoverflow.com/questions/30662221/rails-4-attendance-system
https://stackoverflow.com/questions/11991892/rails-3-taking-attendance-form-how-to-create-multiple-records
https://stackoverflow.com/questions/40485042/generate-attendance-view-form-in-rails-for-all-students

  • a dozen more

Form 1 - mark students attendnace
https://docs.google.com/drawings/d/1sM-quaY87Xp86Utp1yQTIrqwTRjzn3k1Fqq92MadaG8/edit
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
https://docs.google.com/drawings/d/10zi_c7dxHMdGC3PpUhQh70N4rFN_0eYMi5wveGxy-gs/edit
I'm getting fancy I know but the idea would be select all / select one / select a few and record hours for each student.

Models

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

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.

Posted in School System

Consigo pero me falta practica con la escritura.

What are you trying to do with your app?

Posted in What is your dream app?

Currently working on:

  • attendnace app inspired by classdojo but for wife's non-profit
  • angie's list type site for renters to check out what previous renters thought about the rental
  • parent app lunch menu maker for picky eaters based on favorite foods

DreamApp - see above

Posted in School System

Hi Jorge, were you able to check out that blog post to help you get started?

Posted in School System

Working on something similar and I was stuck on this too but i'm only ahead of you by a few steps. Do you have any of your models set up yet? How far along are you?

I used this post to help me naviagte the attendance recording but I'm stuck on the ability to post attendnace for multiple studetns at once.

Check it out and let chat me up on the slack group.
https://railsforum.com/topic/1973-need-help-with-designing-a-classroom-attendance-model/