module Hippo::Concerns::TrackModifications
Extends Rails
updated_by and created_by timestamps to also track who created and updated the model. It reads the current user's id from User.current_id
when saving and updating the record The class_name for the created_by and updated_by is set to {Hippo::Configuration#user_model}
Private Instance Methods
_record_user_to_column( column )
click to toggle source
# File lib/hippo/access/track_modifications.rb, line 54 def _record_user_to_column( column ) user_id = Hippo::User.current_id ? Hippo::User.current_id : 0 write_attribute( column, user_id ) if self.class.column_names.include?( column ) end
change_tracking_fields()
click to toggle source
# File lib/hippo/access/track_modifications.rb, line 74 def change_tracking_fields %w{updated_by_id created_by_id updated_at created_at} end
record_create_modifications()
click to toggle source
# File lib/hippo/access/track_modifications.rb, line 59 def record_create_modifications if self.class.should_record_user_modifications? _record_user_to_column('updated_by_id') _record_user_to_column('created_by_id') end true end
record_update_modifications()
click to toggle source
# File lib/hippo/access/track_modifications.rb, line 67 def record_update_modifications if self.class.should_record_user_modifications? && should_record_timestamps? _record_user_to_column('updated_by_id') end true end