How can i track the object details?

戏子无情 提交于 2020-02-08 11:04:17

问题


I have Student Model Like

class Student < ApplicationRecord
    belongs_to :classroom, optional: true
end

Classroom model Like:

class Classroom < ApplicationRecord
    has_many :students,dependent: :destroy
    has_many :teachers, dependent: :destroy
    belongs_to :school, dependent: :destroy
end

Now i wants to track the every students of every classroom.

i want the following detail with notice and date and display in the show page

http://localhost:3000/school/1/students/68

For exe. student which has id:68 and his classroom_id: 2 i want to show the all activities of student which has id 67.

When particular student is created, updated, change his classroom_id, who create the students...etc

Now i want to display the that student activity in show.html.erb

images is here where i need all this stuff

This is the show page of student and I want these all activities of this student here

Is there need to create the table ?? i want the description of activities as well. can anyone help me to solve this ??

i want to display the activities as bellow

I wanto display all activities like


回答1:


You can create some has_many :through associations to keep history of associations changes. Also you can track for changes in your object with Active Model Dirty: https://api.rubyonrails.org/classes/ActiveModel/Dirty.html

Or create separate table/tables for tracking all changes.

Or if you don't want to implement it all by yourself, you can use gem for this case: I think that is the most popular one:
https://github.com/paper-trail-gem/paper_trail

Other popular ones:
https://github.com/chaps-io/public_activity
https://github.com/michelson/espinita



来源:https://stackoverflow.com/questions/59987284/how-can-i-track-the-object-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!