module Skr::Concerns::TrackModifications
Extends Rails updated_by and created_by timestamps to also track who created and updated the model. It reads the current user from UserProxy.current_id
when saving and updating the record The class_name for the created_by and updated_by is set to {Skr::Core::Configuration#user_model}
Private Instance Methods
_record_user_to_column( column )
click to toggle source
# File lib/skr/concerns/track_modifications.rb, line 23 def _record_user_to_column( column ) user_id = Skr::UserProxy.current_id ? Skr::UserProxy.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/skr/concerns/track_modifications.rb, line 43 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/skr/concerns/track_modifications.rb, line 28 def record_create_modifications if self.record_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/skr/concerns/track_modifications.rb, line 36 def record_update_modifications if self.record_modifications && should_record_timestamps? _record_user_to_column('updated_by_id') end true end