Rails Tiptap Autosave 标志

Rails Tiptap Autosave

社区
obie
rails-tiptap-autosave

Add Tiptap rich text editing with debounced autosave to Rails models using Stimulus. Stores markdown in text columns (not ActionText). Covers installation, Stimulus controller, shared partials, Turbo cache handling, and optional change tracking.

Add to TypingMind

概览

发布者obie
代码仓库skills
技能名称rails-tiptap-autosave
星标数
101
复刻数
6
附带文件
4
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 4 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 obie 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Rails Tiptap Autosave AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/obie/skills/tree/main/skills/rails-tiptap-autosave
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/obie/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/rails-tiptap-autosave .claude/skills/rails-tiptap-autosave
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Rails Tiptap Autosave,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Rails Tiptap Autosave。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Rails Tiptap Autosave 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Rails Tiptap Autosave

Add rich text editing with automatic background saving to any Rails model using Tiptap, Stimulus, and markdown stored in plain text columns.

When to Use This Skill

Invoke this skill when:

  1. Adding rich text editing to Rails models without ActionText
  2. Implementing inline autosave for text fields
  3. Integrating Tiptap editor with Stimulus controllers
  4. Building content editing UIs with formatting toolbars
  5. Debugging Tiptap + Turbo cache conflicts

Architecture Overview

Key decision: Markdown in text columns, NOT ActionText.

Why this approach:

  • No extra tables or polymorphic attachments
  • Content is plain text -- easy to query, diff, and version
  • Markdown renders cleanly in non-browser contexts (emails, APIs, CLI)
  • Simpler mental model than ActionText's rich text blobs

How it works:

  1. Tiptap editor (initialized via Stimulus) converts user input to markdown
  2. On every keystroke (debounced 1 second), PATCH to autosave endpoint
  3. Controller saves markdown to a text column via update_column
  4. Status indicator shows "Saving..." -> "Saved" -> fades

Key Files

FilePurpose
app/javascript/controllers/rich_text_editor_controller.jsTiptap Stimulus controller
app/views/shared/_rich_text_field.html.erbReusable editor partial
app/views/shared/_bubble_menu.html.erbFormatting toolbar

Core Patterns

1. Installation & Build Pipeline

npm packages, @rails/request.js for CSRF, JS bundler setup (Tiptap does NOT work with importmap), and editor CSS.

See: references/installation.md

2. Stimulus Controller

The full rich_text_editor_controller.js -- handles Tiptap initialization, debounced autosave, BubbleMenu target relocation, Turbo cache cleanup, and bubble menu formatting commands.

See: references/stimulus-controller.md

3. View Partials

Reusable _rich_text_field.html.erb and _bubble_menu.html.erb partials with Stimulus data attributes.

See: references/partials.md

4. Optional Audit Trail

Debounced change tracking that groups rapid edits into single audit events.

See: references/audit-trail.md

Adding Rich Text to a Model

Quick step-by-step for any model (Article, Post, Page, etc.):

Step 1: Add a text column

ruby
class AddBodyToArticles < ActiveRecord::Migration[7.1]
  def change
    add_column :articles, :body, :text
  end
end

Use text, NOT string. The string type has a 255-character limit -- far too small for rich text content.

Step 2: Add the autosave route

ruby
# config/routes.rb
resources :articles do
  member do
    patch :autosave
  end
end

Step 3: Add the autosave controller action

ruby
class ArticlesController < ApplicationController
  before_action :set_article, only: [:show, :edit, :update, :autosave]

  AUTOSAVE_FIELDS = %w[body summary notes].freeze

  def autosave
    field = params[:field].to_s
    unless AUTOSAVE_FIELDS.include?(field)
      return render json: { error: "field not allowed" }, status: :bad_request
    end

    @article.update_column(field.to_sym, params[:value])
    render json: { status: "saved" }
  end
end

Key details:

  • update_column bypasses validations and callbacks -- important for autosave performance
  • Field whitelist prevents saving to arbitrary columns (security)
  • Returns JSON (not HTML) since this is a background save
  • set_article must include :autosave in the only: list

Step 4: Render the shared partial in your view

erb
<%= render "shared/rich_text_field",
    url: autosave_article_path(@article),
    field: "body",
    content: @article.body,
    placeholder: "Write your article...",
    label: "Body",
    subtitle: "-- supports markdown formatting" %>

Common Pitfalls

  1. Wrong column type: Must be text, not string (255 char limit will silently truncate content)
  2. Missing route: patch :autosave member route must exist or you get 404s on save
  3. Missing before_action: set_article (or equivalent) must include :autosave in its only: list
  4. Broadcast conflicts: Never use broadcasts_refreshes on models with Tiptap -- Turbo morphing destroys editor state mid-edit. If you need real-time updates, scope broadcasts to exclude the editing user.
  5. ActionText confusion: This pattern is NOT ActionText. Content is plain markdown in text columns. Do not add has_rich_text declarations.
  6. Importmap incompatibility: Tiptap's packages are not ESM-compatible with importmap. You MUST use esbuild, vite, or another JS bundler. See references/installation.md for setup.
  7. BubbleMenu target relocation: Tiptap's BubbleMenu extension moves the DOM element outside the Stimulus controller scope, making this.bubbleMenuTarget unreachable after initialization. The controller must save a reference before calling new Editor(). This is the #1 source of "target not found" errors. See references/stimulus-controller.md.
  8. Turbo cache stale editors: Without proper turbo:before-cache handling, back-button navigation shows a broken editor that won't reinitialize. The controller must destroy the editor and restore the DOM before Turbo caches the page. See references/stimulus-controller.md.

Multiple Rich Text Fields on One Page

Each field gets its own controller instance via its own render call. The field value tells the autosave endpoint which column to update:

erb
<%= render "shared/rich_text_field",
    url: autosave_article_path(@article),
    field: "body",
    content: @article.body,
    placeholder: "Article body...",
    label: "Body" %>

<%= render "shared/rich_text_field",
    url: autosave_article_path(@article),
    field: "summary",
    content: @article.summary,
    placeholder: "Brief summary...",
    label: "Summary" %>

Each instance is fully independent -- separate editor, separate autosave, separate status indicator.

Rendering Saved Markdown

Since content is stored as markdown, you need to render it to HTML for display. Common approaches:

ruby
# Gemfile
gem "redcarpet"
# or
gem "commonmarker"
ruby
# app/helpers/markdown_helper.rb
module MarkdownHelper
  def render_markdown(text)
    return "" if text.blank?

    renderer = Redcarpet::Render::HTML.new(hard_wrap: true, filter_html: true)
    markdown = Redcarpet::Markdown.new(renderer,
      autolink: true,
      tables: true,
      fenced_code_blocks: true,
      strikethrough: true
    )
    markdown.render(text).html_safe
  end
end
erb
<%# In your show view %>
<div class="prose prose-sm max-w-none">
  <%= render_markdown(@article.body) %>
</div>

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Rails Tiptap Autosave AI 技能有什么作用?

Add Tiptap rich text editing with debounced autosave to Rails models using Stimulus. Stores markdown in text columns (not ActionText). Covers installation, Stimulus controller, shared partials, Turbo cache handling, and optional change tracking.

为什么在 TypingMind 中使用 Rails Tiptap Autosave?

因为您只需安装一次,就能搭配任何模型使用。Rails Tiptap Autosave 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Rails Tiptap Autosave?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/obie/skills/tree/main/skills/rails-tiptap-autosave。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Rails Tiptap Autosave?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Rails Tiptap Autosave 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Rails Tiptap Autosave 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Rails Tiptap Autosave AI 技能免费吗?

是的。obie 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇