You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails 7.0中Active Text附件无法持久化保存问题求助

Rails 7.0 Action Text附件无法持久化问题

我刚把应用升级到Rails 7.0,尝试使用Action Text,基础文本编辑功能正常,但附件无法保存。日志显示文件已成功上传至Active Storage,但创建或更新对象时,附件并未被持久化到Action Text的内容中。


上传日志(文件已成功上传至Active Storage)

Processing by ActiveStorage::DirectUploadsController#create as JSON
  Parameters: {"blob"=>{"filename"=>"Screenshot 2025-03-24 at 8.48.41 AM.png", "content_type"=>"image/png", "byte_size"=>727212, "checksum"=>"c1tac+uhxMTNPxNfAVDcYA=="}, "direct_upload"=>{"blob"=>{"filename"=>"Screenshot 2025-03-24 at 8.48.41 AM.png", "content_type"=>"image/png", "byte_size"=>727212, "checksum"=>"c1tac+uhxMTNPxNfAVDcYA=="}}}
  TRANSACTION (0.1ms)  BEGIN
  ActiveStorage::Blob Create (2.2ms)  INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "byte_size", "checksum", "created_at", "service_name") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["key", "gf2kxprcn4tbtftut7x2ms30ks27"], ["filename", "Screenshot 2025-03-24 at 8.48.41 AM.png"], ["content_type", "image/png"], ["byte_size", 727212], ["checksum", "c1tac+uhxMTNPxNfAVDcYA=="], ["created_at", "2025-03-30 20:22:45.464660"], ["service_name", "google"]]
  TRANSACTION (0.5ms)  COMMIT
  GCS Storage (3.3ms) Generated URL for file at key: gf2kxprcn4tbtftut7x2ms30ks27 (https://storage.googleapis.com/pitticketpro-files/gf2kxprcn4tbtftut7x2ms30ks27?GoogleAccessId=production%40pit-ticket-pro.iam.gserviceaccount.com&Expires=1743366465&Signature=xC2FZByZGMVv%2FTVpGo9sAtbRdKrrDhkUkOUhZkrM1OTQOVtqkwWCyHPLl1BVxwJxFhhSXHD8F6tm5HMA6c3Ap4VVKdPABTPmzzWevmDEin1O5Um4jY904QxVItLeBW6fHsU22wIR6WWlyR8ZJXmJbjd1XLyJRVCeVNahQDpQ80ZkpVFIAM8F1TiT8qOlx3aqhEU%2BHJQkSw5aCMKQNelxxFx4eAIbND%2FcgSoGyEKbglktjxPB7BA2AabwuuGvVAJ%2Blg2Y%2BmOQv3FudhJ1qJzXt61OnZ6nw%2FLagYxZA4JzSuGAEBq4vgMfLSgAYLm32y7z9RwnMUjGkNY6vV0ihYvUIA%3D%3D)

Action Text记录(无附件关联)

id: 2,
name: "content",
body: #<ActionText::Content "<div class=\"trix-conte...">,
record_type: "ReleaseNote",
record_id: 2,
created_at: Sun, 30 Mar 2025 15:20:15.986230000 CDT -05:00,
updated_at: Sun, 30 Mar 2025 15:20:15.986230000 CDT -05:00

Body内容(无附件标记)

"<div class=\"trix-content\">\n  <h1>This is a test</h1><div><br></div><div><strong>Release note</strong></div><div><br></div><div>Is this actually working?</div><ol>\n<li>sfdaafdsfasdfadsf</li>\n<li>dddd</li>\n<li>it actually is working</li>\n</ol><div>\n<br>hah<br><br>fsdflksdj flksdk fj<br><br><br><br>\n</div><div>\n<br><br><br>\n</div>\n</div>\n"

环境信息

  • Rails 7.0.8.7
  • Ruby 3.1.6
  • ActionText 7.0.8.7
  • 部署环境:Heroku H-22 dyno
  • 开发环境:M4 Mac
  • 存储服务:Google Storage
  • 开发环境已安装vips

相关代码

控制器代码

class ReleaseNotesController < InheritedResources::Base
  load_and_authorize_resource

  def show
    @release_note = ReleaseNote.last
  end

  def create
    ReleaseNote.create! params.require(:release_note).permit(:title, :content)
    redirect_to release_notes_path
  end

  def update
    @release_note.update(release_note_params)
    redirect_to release_note_path(@release_note)
  end

  private

    def release_note_params
      params.require(:release_note).permit(:title, :content)
    end
end

模型代码

class ReleaseNote < ApplicationRecord
    include ActionText::Attachable
    has_rich_text :content
end

表单代码(ERB)

# = form_with model: release_note do |f|
= simple_form_for @release_note do |f|
  div class="field"
    = f.rich_text_area :content    

  .form-inputs

  <br>
  .form-actions
    = f.button :submit

我已在开发环境安装vips,请问还有哪些可尝试的解决方向?


内容的提问来源于stack exchange,提问作者Michael Bordelon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 14:25:56