How would you approach adding students to classes?
Student resources. Students belong to classes through
ClassMemberships. So far students have been added to classes using a grid of class checkboxes on the Edit Student page. Now I'm working on a feature to add students to classes directly from the Edit Class page.
I have a search input that
remote loads the student search results in a div. I want each student name to be clickable to add them to the class (ie create a new
Would you use something like the
button_to tag to create a tiny form for each student name? Where would you send the form? The
class_membership#create controller action, passing in the
student.id? Or is there a more Rails-y way to do it? (I'm aware the whole process I'm using here isn't very Rails-y)
# school_class.rb class SchoolClass < ActiveRecord::Base ... has_many :class_memberships has_many :students, through: :class_memberships ... end
# student.rb class Student < ActiveRecord::Base ... has_many :class_memberships has_many :school_classes, through: :class_memberships ... end
# class_membership.rb class ClassMembership < ActiveRecord::Base ... belongs_to :student belongs_to :school_class ... end
What about this code?
has_many :students, through: :attendances, source: :student, dependent: :add