最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ruby - ActiveText on Rails 7.0 not saving Attachments - Stack Overflow

programmeradmin4浏览0评论

I just upgraded my app to Rails 7.0 (finally). I wanted to try out Active Text. I got the basics working, but it will not save attachments.

I see it uploading to 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 (.iam.gserviceaccount&Expires=1743366465&Signature=xC2FZByZGMVv%2FTVpGo9sAtbRdKrrDhkUkOUhZkrM1OTQOVtqkwWCyHPLl1BVxwJxFhhSXHD8F6tm5HMA6c3Ap4VVKdPABTPmzzWevmDEin1O5Um4jY904QxVItLeBW6fHsU22wIR6WWlyR8ZJXmJbjd1XLyJRVCeVNahQDpQ80ZkpVFIAM8F1TiT8qOlx3aqhEU%2BHJQkSw5aCMKQNelxxFx4eAIbND%2FcgSoGyEKbglktjxPB7BA2AabwuuGvVAJ%2Blg2Y%2BmOQv3FudhJ1qJzXt61OnZ6nw%2FLagYxZA4JzSuGAEBq4vgMfLSgAYLm32y7z9RwnMUjGkNY6vV0ihYvUIA%3D%3D)

So... it seems like it is trying to save it, but then when I create or update the object, it is not persisting the attachment.

Here is the content of an active text record I tried to attach to...

 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"

I did install vips on my Mac. Is there anything else that I should consider trying out.

Thanks for any help

Rails 7.0.8.7 Ruby 3.1.6 ActionText 7.0.8.7

I host this in Heroku on a H-22 dyno but do dev on a modern M4 Mac.

I use google storage.

Here is the controller:

    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

Here's the model:

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

Here is the form:

/ = 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

发布评论

评论列表(0)

  1. 暂无评论