问题
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