Sha256: 39fcb4df6303f13d844a9382b616025f6b32868add53ba70489a0303ada639d8
Contents?: true
Size: 722 Bytes
Versions: 2
Compression:
Stored size: 722 Bytes
Contents
# frozen_string_literal: true # Just works with effective_resources controller to track views on show action # Add acts_as_trackable to your model # add_column :things, :tracks_count, :integer, default: 0 module ActsAsTrackable extend ActiveSupport::Concern module Base def acts_as_trackable(*options) @acts_as_trackable = options || [] include ::ActsAsTrackable end end included do has_many :tracks, -> { order(:id) }, as: :owner, class_name: 'Effective::Track' end module ClassMethods def acts_as_trackable?; true; end end # Instance Methods def track!(action: 'view', user: nil, details: nil) tracks.create!(action: action, user: user, details: details) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
effective_logging-4.3.1 | app/models/concerns/acts_as_trackable.rb |
effective_logging-4.3.0 | app/models/concerns/acts_as_trackable.rb |