All threads / How would you approach adding students to classes?
Ask A Question


You’re not receiving notifications from this thread.

How would you approach adding students to classes?

Daniel Weaver asked in Rails

I have SchoolClass and 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 ClassMembership).

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 and 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
# student.rb
class Student < ActiveRecord::Base
  has_many :class_memberships
  has_many :school_classes, through: :class_memberships
# class_membership.rb
class ClassMembership < ActiveRecord::Base
  belongs_to :student
  belongs_to :school_class

Hi, I am very glad to join this informative discussion where you explained how would we approach adding students to classes. I hope this information will be helpful to many people. As a beginner at this platform, I am also learned from this post. Actually, I am a first-year student of computer science. So I often take programming assignment help from Eduzaurus writing services company. Interested people can check the website review where they are providing different types of educational writing services for worldwide students, especially for those who are struggling to write their assignments. I also love to learn online that's why I joined a programming course on this platform.

Thank you for sharing this good information.

I am very grateful to you for the explanation.

Thank you so much for these recommendations!

Hi all. This is an important topic for discussion. Daniel, of course, if you add such a function to add students to the class, it will be much more convenient.

Thank you for share the message

It is important to the education of US students because it gives them a sense of what should be considered constitutional principles. Learning the reasoning behind these principles is a good way to get a better understanding of the why and how of government.

Join the discussion

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

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

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

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.