From majestic-rails
Adds polymorphic activity timelines with live Turbo Stream updates to Rails models. Tracks field changes, status transitions, comments, attachments via migrations, concerns, broadcasting, optional AI summaries.
How this skill is triggered — by the user, by Claude, or both
Slash command
/majestic-rails:rails-activity-timelineThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Add a polymorphic activity timeline with live Turbo Stream updates to any Rails model. Track field changes, status transitions, comments, attachments, and more with configurable icons and colors per action type.
Add a polymorphic activity timeline with live Turbo Stream updates to any Rails model. Track field changes, status transitions, comments, attachments, and more with configurable icons and colors per action type.
Four components:
ActivityEvent model (polymorphic) — the core event recordActivityTrackable concern — auto-logs child model lifecycle events on a parent's timelinebelongs_to :trackable, polymorphic: true # parent entity whose timeline this belongs to
belongs_to :subject, polymorphic: true, optional: true # related entity being acted upon
belongs_to :user, optional: true # who performed the action
ACTIONS = %w[
created updated destroyed
field_updated status_changed
comment_added
attachment_added attachment_removed
assigned unassigned
relationship_added relationship_removed
tag_added tag_removed
].freeze
Add domain-specific actions (e.g., published, approved) to ACTIONS and the DISPLAY hash.
Migration, full ActivityEvent model, ActivityTrackable concern, and prerequisites.
See: references/setup.md
Stream naming convention, broadcast methods, partial routing, shared timeline partial, and event partial.
See: references/broadcasting.md
The DISPLAY hash, adding custom actions with icons, display methods, customizing the event partial.
See: references/display.md
AI-generated change summaries for field_updated events with long text changes.
See: references/ai-summaries.md
class Project < ApplicationRecord
has_many :activity_events, as: :trackable, dependent: :destroy
end
In ActivityEvent#broadcast_partial, add your model to the case statement:
def broadcast_partial
case trackable_type
when "Project", "Article" then "activity_events/activity_event"
else "activity_events/activity_event"
end
end
<%= render "shared/activity_timeline", record: @project %>
# Status change
ActivityEvent.create!(
trackable: @project,
user: current_user,
action: "status_changed",
details: { from_status: "draft", to_status: "active" }
)
# Field change
if @project.saved_change_to_status?
ActivityEvent.create!(
trackable: @project,
user: current_user,
action: "field_updated",
details: { field: "status", from: @project.status_previously_was, to: @project.status }
)
end
For child models that auto-log on a parent's timeline:
class Comment < ApplicationRecord
include ActivityTrackable
def activity_trackable = post
def activity_action_created = "comment_added"
def activity_action_destroyed = "comment_removed"
def activity_label = body.truncate(60)
def activity_user = user
end
Override activity_created_details or activity_destroyed_details for additional metadata:
def activity_created_details
{ file_size: byte_size, content_type: content_type }
end
@project.activity_events.timeline # recent, includes user, limit 50
@project.activity_events.by_type("status_changed")
ActivityEvent.where(subject: @task).recent
Wrong trackable — events appear on wrong timeline. activity_trackable must return the parent, not self.
Missing broadcast routing for new types — add new model types to the broadcast_partial case statement; without this broadcasts silently fail.
Missing actions in ACTIONS + DISPLAY — validation rejects unrecognized actions. Always add both.
N+1 on timeline — always use .timeline scope (includes :user). Add associations to the scope, not the partial.
Turbo Stream not updating — turbo_stream_from tag in view must match stream name in broadcast method. Convention: "#{record_type}_{id}_activity".
turbo-railsUser model (optional, for attribution)npx claudepluginhub majesticlabs-dev/majestic-marketplace --plugin majestic-railsGuides building reactive Rails apps with Hotwire (Turbo Drive/Frames/Streams, Stimulus): installation, ActionCable/Redis setup, core patterns.
Rails 7+ specialist: optimizes Active Record queries (includes/eager_load), implements Turbo Frames/Streams, configures Action Cable and Sidekiq, writes RSpec tests.
Implements Hotwire features with Turbo Drive, Turbo Frames, and Turbo Streams in Rails 8, covering morphing, broadcasts, lazy loading, and real-time updates.