我有喜欢的学生模特
class Student < ApplicationRecord
belongs_to :classroom, optional: true
end
教室模式,例如:
class Classroom < ApplicationRecord
has_many :students,dependent: :destroy
has_many :teachers, dependent: :destroy
belongs_to :school, dependent: :destroy
end
现在我想跟踪每个教室的每个学生。
我想要以下带有通知和日期的详细信息,并显示在显示页面上
对于exe。 学生的ID:68,他的教室ID:2 我想显示ID为67的学生的所有活动。
创建,更新特定学生后,更改其创建学生的教室ID ...等
现在我想在show.html.erb中显示该学生活动
图像是我需要所有这些东西的地方
This is the show page of student and I want these all activities of this student here
是否需要创建表? 我也想对活动进行描述。 谁能帮助我解决这个问题?
我希望将活动显示为
答案 0 :(得分:0)
您可以创建一些has_many :through
关联以保留关联更改的历史记录。
您还可以使用活动模型肮脏来跟踪对象中的更改:
https://api.rubyonrails.org/classes/ActiveModel/Dirty.html
或创建单独的一个或多个表以跟踪所有更改。
或者如果您不想自己全部实现,则可以在这种情况下使用gem:
我认为那是最受欢迎的:
https://github.com/paper-trail-gem/paper_trail
其他热门:
https://github.com/chaps-io/public_activity
https://github.com/michelson/espinita