我已經學習Rails大約兩個月了。我正在爲教師創建一個應用程序,以跟蹤學生的進度。我已經有了「作業」模型,可以讓教師爲課堂添加新作業,並且我已經有了「用戶」模型,以便教師和學生都可以登錄到應用程序。還有一個「課堂」模式,每個教室都有多個學生和多個作業。使用Rails創建電子表格式表單
其中一個主要觀點需要像傳統教師成績冊程序那樣具有電子表格形式。電子表格將使用學生作爲行和分配作爲列。電子表格中的每個單元格都將表示該作業的學生分數。
從我到目前爲止所瞭解到的情況來看,我認爲我的下一步應該是創建一個鏈接學生和作業的連接表,以及第三列「分數」。
我被難倒的部分是創建表單,以便輸入單元格與連接表中的「分數」列相關聯,以便輸入新數字將更改該作業的學生分數。
我確定文章或教程必須存在某個地方爲這個概念,但我還沒有找到任何。至少,我沒有認識到這個目標的解決方案。
預先感謝您的任何指導。
更新,包括代碼適用機型
用戶模型:
class User < ApplicationRecord
attr_accessor :remember_token, :activation_token, :reset_token
before_save :downcase_email
before_create :create_activation_digest
has_many :seminars, dependent: :destroy
# Neccessary for finding all classes that a student is enrolled in
has_many :aulas, dependent: :destroy,
foreign_key: :student_id
validates :first_name, length: {maximum: 25},
presence: true
validates :last_name, length: {maximum: 25},
presence: true
VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
has_secure_password
validates :password, presence: true, length: {minimum: 6}, allow_nil: true
### Several methods that I omitted to keep the question shorter
end
研討會型號: (A「研討會」是一類的時期,但我想避免的話,「類」,因爲我認爲這會導致錯誤)
class Seminar < ApplicationRecord
belongs_to :teacher, class_name: "User",
foreign_key: "user_id"
has_many :aulas, dependent: :destroy
has_many :students, through: :aulas, source: :student
has_many :assignments
validates :user_id, presence: true
validates :name, presence: true, length: { maximum: 40 }
end
禮堂型號:。 (禮堂是西班牙語類同樣,我想避免的話,「類」這個模式升創建學生用戶和研討會(節課的時間)之間的關係「
class Aula < ApplicationRecord
# Aula is the relationship between a student and a classperiod.
belongs_to :student, class_name: "User"
belongs_to :seminar
validates :student_id, presence: true
validates :seminar_id, presence: true
end
分配模式:
class Assignment < ApplicationRecord
belongs_to :seminar
validates :name, presence: true, length: { maximum: 40 }
validates :seminar_id, presence: true
validates :possible, presence: true
end
如果您可以編輯問題並向我展示您的模型(學生,作業和分數)及其關係,我可以更輕鬆地爲您提供幫助,謝謝 –
Haider,謝謝您的建議。我更新了問題以包含所有模型。我還沒有「Score」的模型。我目前的計劃是將其包含在學生/作業連接表中。但我願意改變這一點。 –