Action Text attachments not working on production

1.1k views Asked by At

We're currently using Active Storage to upload avatar images to Amazon S3 which is working great on local as well as production

class User < ApplicationRecord
  has_one_attached :avatar
end

I'm now trying to use Action Text and followed the directions on Rails Guides which is working perfectly on localhost

class Course < ApplicationRecord 
  belongs_to :user
  has_rich_text :content
end

When I deploy to production, however, the rich text formatting works but attachments are not being uploaded to S3 which surprised me since I assumed it's using the same active storage credentials that we used for the avatar image uploads. Strangely it's populating the active_storage_blobs table with the filenames even though they are not being uploaded or being referenced by active_storage_attachments.

Could someone help?

2

There are 2 answers

2
vince On

Turns out the default is direct uploads in Action Text (unlike Active Storage attachments) and it works after setting up CORS on S3

0
ggsp On

In order to configure CORS on AWS, you need to change the settings for your production bucket.

An example CORS configuration, in JSON, would look like so:

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "https://www.example.com"
        ],
        "ExposeHeaders": []
    }
]

Where https://www.example.com is the URL of your Rails app. Make sure you do not allow all origins (which you would do by replacing the URL with the * wildcard).