action_log.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: admin_action_logs
  5. #
  6. # id :bigint(8) not null, primary key
  7. # account_id :bigint(8)
  8. # action :string default(""), not null
  9. # target_type :string
  10. # target_id :bigint(8)
  11. # created_at :datetime not null
  12. # updated_at :datetime not null
  13. # human_identifier :string
  14. # route_param :string
  15. # permalink :string
  16. #
  17. class Admin::ActionLog < ApplicationRecord
  18. self.ignored_columns += %w(
  19. recorded_changes
  20. )
  21. belongs_to :account
  22. belongs_to :target, polymorphic: true, optional: true
  23. before_validation :set_human_identifier
  24. before_validation :set_route_param
  25. before_validation :set_permalink
  26. scope :latest, -> { order(id: :desc) }
  27. def action
  28. super.to_sym
  29. end
  30. private
  31. def set_human_identifier
  32. self.human_identifier = target.to_log_human_identifier if target.respond_to?(:to_log_human_identifier)
  33. end
  34. def set_route_param
  35. self.route_param = target.to_log_route_param if target.respond_to?(:to_log_route_param)
  36. end
  37. def set_permalink
  38. self.permalink = target.to_log_permalink if target.respond_to?(:to_log_permalink)
  39. end
  40. end